Created
January 31, 2012 19:39
-
-
Save iband/1712472 to your computer and use it in GitHub Desktop.
insertObject:atIndex:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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