简体   繁体   English

[NSObject:AnyObject]和swift中的AnyObject有什么区别

[英]What is difference between [NSObject: AnyObject] and AnyObject in swift

In default template we can find the following code: 在默认模板中,我们可以找到以下代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool

Just wonder why here it is [NSObject: AnyObject]? 只是想知道为什么这里是[NSObject:AnyObject]? rather than AnyObject? 而不是AnyObject? What's the different between them? 他们之间有什么不同?

[NSObject: AnyObject] is a dictionary that allows you to access one object by providing a different object. [NSObject: AnyObject]是一个字典,允许您通过提供不同的对象来访问一个对象。 Simply putting AnyObject means that your program doesn't know whether the parameter is a dictionary, a string, and int, or what, and therefore doesn't know how to handle it. 简单地放置AnyObject意味着你的程序不知道参数是字典,字符串,int,还是什么,因此不知道如何处理它。 Besides, the OS calls that method so you know you are getting a [NSObject: AnyObject] every time, so why not have the parameter type that. 此外,操作系统调用该方法,因此您知道每次都会获得[NSObject: AnyObject] ,所以为什么不使用参数类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM