[英]NSDictionary vs [String:AnyObject] in Swift
I updated an external Swift library, and one of the methods has changed face from: 我更新了一个外部Swift库,其中一种方法已更改了以下内容:
public convenience method(data:NSDictionary?) { ... }
to: 至:
public convenience method(data:[String: AnyObject]?) { ... }
What does this mean? 这是什么意思?
Initially, with the old, @{@"optionA":@YES}
was passed as data
argument. 最初,使用旧的
@{@"optionA":@YES}
作为data
参数传递。 But now with the new I need to pass two items. 但是现在有了新产品,我需要通过两项。 I was thinking to just write
@{@"optionA":@YES,@"optionB":@NO}
, is that correct? 我当时想只写
@{@"optionA":@YES,@"optionB":@NO}
,对吗?
It just means that the parameter is a swift dictionary now and no Objective-C NSDictionary anymore. 这仅表示该参数现在是快速字典,并且不再是Objective-C NSDictionary。
To pass data, just use square brackets instead of curly brackets and remove the "@" (in swift) 要传递数据,只需使用方括号代替大括号并删除“ @”(快速)
["optionA":true, "optionB": false]
If you are calling the method from Objective-C, the method parameter should be exposed as NSDictionary and you were right with @{@"optionA":@YES,"optionB":@NO}
but missed a @-sign before optionB
如果您是从Objective-C调用方法,则该方法参数应显示为NSDictionary,并且您使用
@{@"optionA":@YES,"optionB":@NO}
但是在optionB
之前错过了@ optionB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.