Swift布尔文字(Obj-C @YES @NO等价物)

前端之家收集整理的这篇文章主要介绍了Swift布尔文字(Obj-C @YES @NO等价物)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在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>

读这个:https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/buildingcocoaapps/WorkingWithCocoaDataTypes.html#//apple_ref/doc/uid/TP40014216-CH6-XID_43

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
原文链接:https://www.f2er.com/swift/319835.html

猜你在找的Swift相关文章