Last active
August 29, 2015 14:25
-
-
Save Eluss/ad7b1e1d00f9a49f8978 to your computer and use it in GitHub Desktop.
This file contains 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
- (void)saveTasks { | |
NSMutableArray *tasksToSave = [NSMutableArray new]; | |
for (NSInteger i = 0 ; i < 5; i ++) { | |
NSString *taskName = [NSString stringWithFormat:@"%d", arc4random_uniform(50)]; | |
Task *task = [[Task alloc] initWithName:taskName]; | |
[tasksToSave addObject:task]; | |
} | |
NSString *path = @"~/Documents/"; | |
path = [path stringByAppendingString:@"FILE_NAME"]; | |
path = [path stringByExpandingTildeInPath]; | |
NSMutableDictionary *rootObject = [NSMutableDictionary dictionary]; | |
rootObject[@"myTasks"] = tasksToSave; | |
[NSKeyedArchiver archiveRootObject:rootObject toFile:path]; | |
for (NSInteger i = 0; i < tasksToSave.count; i++) { | |
Task *task = tasksToSave[i]; | |
NSLog(@"Saving task:%@", task.name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment