如何在 Swift 中将 nil 赋值给一个对象。如果直接分配,我会收到错误消息。
最佳答案
nil cannot be used with nonoptional constants and variables. If a constant or variable in your code needs to work with the absence of a value under certain conditions, always declare it as an optional value of the appropriate type
同样重要的是要注意:
Swift’s nil is not the same as nil in Objective-C. In Objective-C, nil is a pointer to a nonexistent object. In Swift, nil is not a pointer—it is the absence of a value of a certain type. Optionals of any type can be set to nil, not just object types
希望对你有帮助!
关于ios - 如何在 Swift 中对对象进行 Nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30612740/