Note that there are some explanatory texts on larger screens.

plurals
  1. POwhat is the best method to store an array of objects on NSUserDefaults
    primarykey
    data
    text
    <p>I want to store xml on the iphone that consists of a number of favourite items chosen by the user of the app. I am using TBXML (inherited from prev dev) and as such this cant write xml, I was thinking of chopping together the xml from each item as a string and then loading this in Like so:</p> <p>tbxml = [[TBXML alloc] initWithXMLString:myXML]</p> <p>This is not ideal but is there limitations / advice for this method and what would be the best place to store this file?</p> <p>Many thanks</p> <p>edit</p> <p>The user favourites an item in a UITableView, these can then be viewed in another UITableView called 'My Favourites'. The UITableViewController displays the content from an xml file returned from a server. I was trying to make things simple for me to effectively append each 'items' xml to a large string and then store that string somewhere - either in a file or in NSUserDefaults</p> <p>ideally I could save an array of objects as they are added to favourites to be read back in later.</p> <p>the objects are created like so</p> <pre><code>@interface Playlist : NSObject { NSURL *imagePath; NSString *title; NSString *subTitle; NSString *mediaType; NSString *artistName; NSString *id; } @property (nonatomic, retain) NSURL *imagePath; @property (nonatomic, retain) NSString *title; @property (nonatomic, retain) NSString *subTitle; @property (nonatomic, retain) NSString *mediaType; @property (nonatomic, retain) NSString *artistName; @property (nonatomic, retain) NSString *id; @end </code></pre> <p>is there a way of saving an array of objects like the one above in NSUserDefaults?</p> <p>thanks</p> <p>EDIT 2 I went with NSUserDefaults and maintained an ID for each item as an array</p> <p>very easy to access and update, I made a PlaylistDataController class with methods in there like this one to add an item to my 'MyPlaylistArray' in the user defaults</p> <pre><code>-(void) addItemToPlaylist: (NSString*) myID { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSMutableArray *myPlaylistArray = [NSMutableArray arrayWithArray:[defaults objectForKey:@"MyPlaylistArray"]]; [myPlaylistArray addObject:myID]; [defaults setObject:myPlaylistArray forKey:@"MyPlaylistArray"]; [defaults synchronize]; } </code></pre> <p>Hope it helps someone</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload