-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPersistentStore.m
More file actions
34 lines (30 loc) · 1.18 KB
/
PersistentStore.m
File metadata and controls
34 lines (30 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// PersistentStore.m
// Connect5
//
// Created by Mohammed Eldehairy on 10/9/13.
// Copyright (c) 2013 Mohammed Eldehairy. All rights reserved.
//
#import "PersistentStore.h"
@implementation PersistentStore
+ (NSMutableString *)applicationDocumentsDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSMutableString *basePath = ([paths count] > 0) ? [NSMutableString stringWithString:[paths objectAtIndex:0]] : nil;
return basePath;
}
+(NSString*)filePath
{
return [[self applicationDocumentsDirectory ] stringByAppendingPathComponent:@"LastGame"];
}
+(void)persistGame:(GameEntity *)game
{
//NSDictionary *Data = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:game.graph,[NSNumber numberWithInt:game.score], nil] forKeys:[NSArray arrayWithObjects:@"graph",@"score", nil]];
// [[NSUserDefaults standardUserDefaults] setObject:Data forKey:LAST_GAME_KEY];
// [[NSUserDefaults standardUserDefaults] synchronize];
[NSKeyedArchiver archiveRootObject:game toFile:[self filePath]];
}
+(GameEntity*)getLastGame
{
return [NSKeyedUnarchiver unarchiveObjectWithFile:[self filePath]];
}
@end