JAL JAL - 1 year ago 130
iOS Question

Init an empty NSZone struct with Swift 3

In Swift 2, I was able to initialize an empty

struct like so:

let z = NSZone() // ObjectiveC.NSZone

I used this to stub test calls that required
. 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
instead of the old
initializer which initialized
with a

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

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download