在Objective-C中,您可以键入@YES而不是[NSNumber numberWithBOOL:YES].这使得代码更加简洁.
在Swift中,我必须编写NSNumber.numberWithBool(true),这是一种丑陋.
在Swift中有相当于@YES和@NO吗?
在此先感谢您的帮助!
这是真假
xcrun swift Welcome to Swift! Type :help for assistance. 1> import Foundation 2> var t : NSNumber = true t: __NSCFBoolean = {} 3> var f : NSObject = false f: __NSCFBoolean = {} 4>
Swift automatically bridges certain native number types,such as Int and Float,to NSNumber. This bridging lets you create an NSNumber from one of these types
All of the following types are automatically bridged to NSNumber:
- Int
- UInt
- Float
- Double
- Bool