JAL JAL - 5 months ago 27
iOS Question

Init an empty NSZone struct with Swift 3

In Swift 2, I was able to initialize an empty

NSZone
struct like so:

let z = NSZone() // ObjectiveC.NSZone


I used this to stub test calls that required
NSZone
. With Swift 3, the interface was changed so that the initializer is no longer available:

Swift 2.3:

public struct NSZone : NilLiteralConvertible {
public init()
/// Create an instance initialized with `nil`.
public init(nilLiteral: ())
}


Swift 3:

public struct NSZone {
}


Is Apple pushing to use an optional
NSZone
instead of the old
NSZone()
initializer which initialized
NSZone
with a
nil
value?

Try to extend
NSZone
to add an initializer results in an error:

extension NSZone {
init() { } // Return from initializer without initializing all stored properties
}

Answer

Per the Swift open source project's design doc for importing ObjC API into Swift 3:

Nullable NSZone parameters are given a default value of nil. Zones are essentially unused in Swift and should always be nil.

If you're testing any calls that require a zone, you should be passing nil anyway.