Xcode7 e veloce, il mio codice: il codiceNon può convertire il valore di tipo '[NSObject: ANYOBJECT]' al tipo di argomento previsto '[String: ANYOBJECT]'
func loadDefaults() {
let settingBundle = NSBundle.mainBundle().pathForResource("Settings", ofType: "bundle")
if settingBundle == nil {
return
}
let root = NSDictionary(contentsOfFile: settingBundle!.stringByAppendingString("Root.plist"))
let prefrences = root?.objectForKey("PreferenceSpecifiers") as! Array<NSDictionary>
let defautlsToRegister = NSMutableDictionary(capacity: root!.count)
for prefrence in prefrences {
let key = prefrence.objectForKey("Key") as! String!
if key != nil {
defautlsToRegister.setValue(prefrence.objectForKey("DefaultVale"), forKey: key!)
}
}
NSUserDefaults.standardUserDefaults().registerDefaults(defautlsToRegister as [NSObject: AnyObject])
}
Problema:
NSUserDefaults.standardUserDefaults().registerDefaults(defautlsToRegister as [NSObject: AnyObject])
avvertenze costruzione
Impossibile convertire il valore di tipo '[NSObject: ANYOBJECT]' al tipo di argomento previsto '[String: ANYOBJECT]'
codice di cambiamento:
NSUserDefaults.standardUserDefaults().registerDefaults(defautlsToRegister as [String: AnyObject])
costruzione avvertimenti
'NSMutableDictionary' non è convertibile a '[String: ANYOBJECT]'
Si prega di insegnarmi come fare? Grazie.
Si prega di mostrare esempio di ' defautlsToRegister 'come tipo –
Usa l'aiuto di' as! ', come suggerito in http://stackoverflow.com/questions/24099165/how-do-i-convert-an-nsdictionary-to-a-swift-dictionarystring-nsobject? – Tali