My code snipet as follows …:
let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) { SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)) }
… does no longer compile with the following error which I don't understand:
"'init' is unavailable: use 'withMemoryRebound(to:capacity:_)' to temporarily view memory as another layout-compatible type."
What to do to fix it?
From the Release Notes of Xcode 8 beta 6:
- An
Unsafe[Mutable]RawPointer
type has been introduced, replacingUnsafe[Mutable]Pointer<Void>
. Conversion fromUnsafePointer<T>
toUnsafePointer<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)
In your case, you may need to write something like this:
let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) { $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress) } }
Replace
let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) { SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)) }
with
guard let defaultRouteReachability = withUnsafePointer(to: &zeroAddress, { $0.withMemoryRebound(to: sockaddr.self, capacity: 1) { SCNetworkReachabilityCreateWithAddress(nil, $0) } }) else { return false }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With