mercredi 22 octobre 2014

Synchronise array stored in NSUserDefaults?


Vote count:

0




I've just tried using an updated version of my app on an iPhone which has the version installed that is currently on the app store. I have added a few new features since the last update which seems to cause the app to crash.


Basically, I added a new array that stores data for notes which was not present in previous versions and this is stored in NSUserDefaults (Not ideal, I know, but I would rather keep it this way for now)


This is the code I have in my table view where the app crashes:



cell.notesLabel.text = (notes.objectAtIndex(indexPath.row)) as? String


The error just states - "Thread 1: breakpoint 1.1" as soon as the table view tab is tapped.


I was discussing this with someone else and they suggested that I need to check for the existence of the array in the defaults and create and synchronise it if it is missing.


I've only been programming for a few months so this doesn't mean a whole lot to me. But I assume I would just need do something like this:



if NSUserDefaults.standardUserDefaults().arrayForKey("notes) == nil {
//Do something?
}


I'm unsure about what he means by synchronise? Anyone have any suggestions?



asked 37 secs ago







Synchronise array stored in NSUserDefaults?

Aucun commentaire:

Enregistrer un commentaire