-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhotoGroupStore.m
More file actions
84 lines (68 loc) · 1.98 KB
/
PhotoGroupStore.m
File metadata and controls
84 lines (68 loc) · 1.98 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// PhotoGroupStore.m
// Metasome
//
// Created by Omar Metwally on 9/12/13.
// Copyright (c) 2013 Logisome. All rights reserved.
//
#import "PhotoGroupStore.h"
#import "PhotoGroup.h"
@implementation PhotoGroupStore
@synthesize photoGroupArray;
+(PhotoGroupStore *)sharedStore
{
static PhotoGroupStore *sharedStore = nil;
if (!sharedStore) {
sharedStore = [[super allocWithZone:nil] init];
}
return sharedStore;
}
+(id)allocWithZone:(NSZone *)zone
{
return [self sharedStore];
}
-(id)init
{
self = [super init];
if (self) {
NSString *path = [self itemArchivePath];
photoGroupArray = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
NSLog(@"unarchived %i photo groups", [photoGroupArray count]);
}
return self;
}
-(void)moveItemAtIndex:(int)from toIndex:(int)to
{
if (from == to) return;
PhotoGroup *g = [photoGroupArray objectAtIndex:from];
[photoGroupArray removeObjectAtIndex:from];
[photoGroupArray insertObject:g atIndex:to];
}
-(NSInteger)numberOfSections
{
return [photoGroupArray count];
}
-(NSString *)sectionHeader:(int)sec
{
return @"Photo Groups";
}
-(NSString *)itemArchivePath
{
NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [documentDirectories objectAtIndex:0];
return [documentDirectory stringByAppendingString:@"photoGroups.archive"];
}
-(BOOL)saveChanges
{
NSString *path = [self itemArchivePath];
NSLog(@"%i items in photoGroupArray on saveChanges", [photoGroupArray count]);
return [NSKeyedArchiver archiveRootObject:photoGroupArray toFile:path];
}
-(void)addPhotoGroup:(PhotoGroup *)photoGroup
{
[[[PhotoGroupStore sharedStore] photoGroupArray] addObject:photoGroup];
PhotoGroup *test = [[PhotoGroup alloc] init];
[photoGroupArray addObject:test];
NSLog(@"photoGroupArray now has %i objects",[photoGroupArray count]);
}
@end