Swift - 转换AutoreleasingUnsafeMutablePointer<AnyObject?>值

11

到目前为止,我有这段代码:

var thumbnailErr: NSError?
var thumbnailDictionary: AutoreleasingUnsafeMutablePointer<AnyObject?> = nil
let getItemSucceeded = url.getPromisedItemResourceValue(thumbnailDictionary, forKey: NSURLThumbnailDictionaryKey, error: &thumbnailErr)
if getItemSucceeded {

}

我现在想把thumbnailDictionary转换成字典或NSDictionary。这是我在Objective-C中的做法:

BOOL thumbnailSucceeded = [urlFromPath getPromisedItemResourceValue:thumbnailDictionary forKey:NSURLThumbnailDictionaryKey error:&thumbnailErr];
if (thumbnailSucceeded) {
    NSDictionary *dict = (__bridge NSDictionary *)(void *)thumbnailDictionary;
}

我真的无法想出如何在Swift中做到这一点。求助?

1个回答

23

收到了。传递AutoreleasingUnsafeMutablePointer是不必要的。

var thumbnailErr: NSError?
var thumbnailDictionary: AnyObject?
let getItemSucceeded = url.getPromisedItemResourceValue(&thumbnailDictionary, forKey: NSURLThumbnailDictionaryKey, error: &thumbnailErr)
if getItemSucceeded {
    let dict = thumbnailDictionary as NSDictionary
}

9
感谢您回答自己的问题。当我找到一个与我的问题完全相同的帖子,只看到作者发布“知道了,不用管了”而没有解释他们的解决方案时,我很讨厌。 - Alexander

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接