在下面的方法中,参数声明中的launchOptions
是什么?它是 NSObject 类型数组的可选吗?我对 swift 还很陌生,所以这听起来可能很傻,但我不明白 didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?
是什么意思。非常感谢任何帮助:)
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame:UIScreen.mainScreen().bounds)
self.window!.backgroundColor = UIColor.whiteColor()
self.window!.makeKeyAndVisible()
return true
}
最佳答案
这就是 swift 转换 NSArray 的方式。
Swift bridges between the Array type and the NSArray class. When you bridge from an NSArray object to a Swift array, the resulting array is of type [AnyObject]. An object is AnyObject compatible if it is an instance of an Objective-C or Swift class, or if the object can be bridged to one. You can bridge any NSArray object to a Swift array because all Objective-C objects are AnyObject compatible. Because all NSArray objects can be bridged to Swift arrays, the Swift compiler replaces the NSArray class with [AnyObject] when it imports Objective-C APIs
关于ios - 对 Swift 方法参数的理解存在问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31165571/