简体   繁体   English

使用Swift 3初始化一个空的NSZone结构

[英]Init an empty NSZone struct with Swift 3

In Swift 2, I was able to initialize an empty NSZone struct like so: 在Swift 2中,我能够初始化一个空的NSZone结构,如下所示:

let z = NSZone() // ObjectiveC.NSZone

I used this to stub test calls that required NSZone . 我用这个来测试需要NSZone调用。 With Swift 3, the interface was changed so that the initializer is no longer available: 使用Swift 3,界面已更改,因此初始化程序不再可用:

Swift 2.3: Swift 2.3:

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

Swift 3: 斯威夫特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? Apple是否正在推动使用可选的NSZone而不是旧的NSZone()初始化程序,它使用nil值初始化NSZone

Try to extend NSZone to add an initializer results in an error: 尝试扩展NSZone以添加初始化器导致错误:

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

Per the Swift open source project's design doc for importing ObjC API into Swift 3: 根据Swift开源项目的设计文档 ,将ObjC API导入Swift 3:

Nullable NSZone parameters are given a default value of nil . Nullable NSZone参数的默认值为nil Zones are essentially unused in Swift and should always be nil . 区域在Swift中基本上未使用,应始终nil

If you're testing any calls that require a zone, you should be passing nil anyway. 如果您正在测试任何需要区域的呼叫,则无论如何都应该传递nil

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM