Skip to content

Instantly share code, notes, and snippets.

@iband
Created January 31, 2012 19:39
Show Gist options
  • Save iband/1712472 to your computer and use it in GitHub Desktop.
Save iband/1712472 to your computer and use it in GitHub Desktop.
insertObject:atIndex:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *recents = [defaults objectForKey:RECENT_PHOTO_KEY];
if (!recents) recents = [NSMutableArray array];
if ([recents containsObject:clickedPhoto]) [recents removeObject:clickedPhoto]; //deleting object if we have one to keep the array of unique objects
[recents insertObject:clickedPhoto atIndex:0]; //inserting clicked photo to the beginning of the mutable array
[defaults setObject:recents forKey:RECENT_PHOTO_KEY]; //saving defaults
[defaults synchronize];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment