swift - Cannot convert value of type '[NSObject : AnyObject]' to expected argument type '[String : AnyObject]' -


xcode7 , swift, code:

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)      prefrence in prefrences {         let key = prefrence.objectforkey("key") as! string!         if key != nil {             defautlstoregister.setvalue(prefrence.objectforkey("defaultvale"), forkey: key!)         }     }      nsuserdefaults.standarduserdefaults().registerdefaults(defautlstoregister [nsobject: anyobject]) } 

problem code:

nsuserdefaults.standarduserdefaults().registerdefaults(defautlstoregister [nsobject: anyobject]) 

building warnings

cannot convert value of type '[nsobject : anyobject]' expected argument type '[string : anyobject]'

change code:

nsuserdefaults.standarduserdefaults().registerdefaults(defautlstoregister [string: anyobject]) 

building warnings

'nsmutabledictionary' not convertible '[string : anyobject]'

please teach me how do? thanks.

your defautlstoregister should in following format [string: anyobject]

example: following should work without warning

let defautlstoregister = ["test":10] nsuserdefaults.standarduserdefaults().registerdefaults(defautlstoregister [string: anyobject]) 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -