2014-08-28 6 views
10

Finora ho questo codice:Swift - La conversione di un valore di <AnyObject?> AutoreleasingUnsafeMutablePointer

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

} 

Ora voglio trasformare thumbnailDictionary in un dizionario o NSDictionary. Questo è come lo faccio in Objective-C:

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

non posso per la vita di me capire come fare questo a Swift. Aiuto?

risposta

20

Capito. Passare in un AutoreleasingUnsafeMutablePointer non era necessario.

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

Grazie per aver risposto alla tua domanda. Lo odio quando trovo un post con la domanda esatta che ho, solo che il proprietario pubblichi "capito, non importa" senza spiegare la loro soluzione – Alexander

Problemi correlati