Enr*_*tyo 1 objective-c nsdictionary ios ios6
在iOS 6中我可以这样做:
NSDictionary *d = @{anObject : "key"};
Run Code Online (Sandbox Code Playgroud)
但显然当对象是UIImageView或UIWebView(或者也可能是其他对象)时,它会崩溃:
'NSInvalidArgumentException', reason: '-[UIWebView copyWithZone:]: unrecognized selector sent
Run Code Online (Sandbox Code Playgroud)
将字典声明更改为旧方法有效:
NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys:anObject,@"key", nil];
Run Code Online (Sandbox Code Playgroud)
知道为什么会这样吗?
Mar*_*n R 10
语法是
NSDictionary *d = @{<key> : <value>, ...};
Run Code Online (Sandbox Code Playgroud)
在你的情况下:
NSDictionary *d = @{@"key" : anObject};
Run Code Online (Sandbox Code Playgroud)
所以你的代码试图anObject用作密钥.这失败了UIWebView因为密钥必须符合NSCopying协议.
| 归档时间: |
|
| 查看次数: |
3035 次 |
| 最近记录: |