ios - 对 Swift 方法参数的理解存在问题

标签 ios swift

在下面的方法中,参数声明中的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

here you can find more about Cocoa data types

关于ios - 对 Swift 方法参数的理解存在问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31165571/

相关文章:

ios - 如何使用位置管理器获得准确的速度

iphone - 在包含一组 View 的 TableView 中添加 NSMutableArray

swift - 用户通过拖动垂直线调整 subview 的大小

ios - 方法 "min()"和 "max()"中内置的 Swift 4 数组是否适用于字符串数组?

swift - 为什么String的字节是: and cString: initializers give different results here?

Swift:TableView 不随自定义选项卡栏滚动

ios - 具有全宽和动态高度的 Collection View 单元格

ios - 具有单独 timeleft 的多个 NSTimer

ios - 如何垂直对齐(居中)UITableView 的内容?

php - 如何从 swift 4 向 GET 请求 (PHP) 发出请求