Monday, 15 July 2013

ios - nsuserdefault not saving array - Swift -



ios - nsuserdefault not saving array - Swift -

i can single string save nsuserdefaults not sure why won't save array using below code. sure little utilize pointer.

// // viewcontroller.swift // demouserdefaults // // created chris cantley on 10/7/14. // copyright (c) 2014 chris cantley. rights reserved. // import uikit class viewcontroller: uiviewcontroller { var storenames:[string] = [] override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. storenames.append("billy") storenames.append("chris") // shows strings in array. println(storenames) // puts mutable immutable object allow holdnames = storenames // "should" store object userdefaults... not. nsuserdefaults.standarduserdefaults().setobject(holdnames, forkey: "storenames") nsuserdefaults.standarduserdefaults().synchronize() // displays info in userdefaults... array missing. println(nsuserdefaults.standarduserdefaults().dictionaryrepresentation()) } }

the result...

[billy, chris] [nslanguages: ( en ), appleitunesstoreitemkinds: ( audiobook, "tv-episode", booklet, software, "software-update", "itunes-u", ringtone, "tv-season", movie, mix, newsstand, song, wemix, tone, artist, "podcast-episode", podcast, document, ebook, album, "music-video" ), applekeyboardsexpanded: 1, nsinterfacestyle: macintosh, applekeyboards: ( "en_us@hw=us;sw=qwerty", "emoji@sw=emoji", "en_us@hw=us;sw=qwerty" ), applelanguages: ( en ), names: rob]

note : "names:rob" previous single string save.

figures... post question have spend hours looking reply on own, , minutes later find solution.

anyways, seem nsuserdefaults doesn't "string" changing "nsstring" works.

so alter is...

var storenames:[string] = []

to

var storenames:[nsstring] = []

ios arrays swift nsuserdefaults

No comments:

Post a Comment