我的代码snipet如下…:
@H_502_1@let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) {
SCNetworkReachabilityCreateWithAddress(nil,UnsafePointer($0))
}
…不再编译与以下错误,我不明白:
@H_502_1@"'init' is unavailable: use 'withMemoryRebound(to:capacity:_)' to temporarily view memory as another layout-compatible type."如何解决它?
从Xcode 8 beta 6的发行说明:
原文链接:https://www.f2er.com/swift/321295.html
- An
Unsafe[Mutable]RawPointer
type has been introduced,replacingUnsafe[Mutable]Pointer<Void>
. Conversion fromUnsafePointer<T>
to
UnsafePointer<U>
has been disallowed.Unsafe[Mutable]RawPointer
provides an API for untyped memory access,and an API for binding
memory to a type. Binding memory allows for safe conversion between
pointer types. SeebindMemory(to:capacity:)
,assumingMemoryBound(to:)
,
andwithMemoryRebound(to:capacity:)
. (SE-0107)
在你的情况下,你可能需要这样写:
@H_502_1@let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) { $0.withMemoryRebound(to: sockaddr.self,capacity: 1) {zeroSockAddress in SCNetworkReachabilityCreateWithAddress(nil,zeroSockAddress) } }