In my app i am uploading various types of data such as image, audio, video, text. Now i want that user should be able to view the most recent 100 items uploaded even when he quits and reopens the app. For this i will create a view which will contai a table view. The table view will be populated with the recent 100 items uploaded. Now i want to implement this through NSUserDefaults. For image, audio and video iphone returns their path or URL which i will have to store to NSUserDefaults but the table view has to be populated by an array, so how do i store my file paths to the NSUserDefaults or array and then fetch those items to populate my table view. OR is there any other better option than NSUserDefaults which is easier to implement?
Asked
Active
Viewed 90 times
1 Answers
0
If there is more data than just this, maybe try a sqlite database. If it's just this data, it seems quite overkill to create a database just for it. You could save the array to the NSUserDefaults with something similar to this:
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"sd"] forKey:@"k"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSArray *array = [[NSUserDefaults standardUserDefaults] objectForKey:@"k"];
if( array == nil ) {
//No data
}
else {
for( NSString *string in array ) {
NSLog(@"String: %@",string);
}
}
The draw back is, if you would like to store a custom object in the array, you would need to encode the objects manually, detailed in this post

Community
- 1
- 1

user352891
- 1,181
- 1
- 8
- 14
-
But how do i make sure that there are always 100 items in the array and they keep on replacing with new recent ones? – user2261732 Apr 09 '13 at 13:18
-
Once you have the array from the NSUserDefaults, change it, make a mutable array from it. When you write it back , it will overwrite the old array. It's up to you what the array contains, the above code will store whatever base NSObject derived class you give it. – user352891 Apr 09 '13 at 13:34