-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdataBase.m
More file actions
82 lines (69 loc) · 1.66 KB
/
dataBase.m
File metadata and controls
82 lines (69 loc) · 1.66 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
//
// database.m
// Table
//
// Created by Tyson Lindhardt on 2/1/14.
// Copyright (c) 2014 Tyson Lindhardt. All rights reserved.
//
#import "database.h"
@implementation database
{
NSMutableArray * db;
}
-(id)init
{
if(self = [super init])
{
db = [[NSMutableArray alloc]init];
}
return self;
}
-(id)initWithArray:(NSMutableArray *)array
{
if(self = [super init])
{
if(!array)
db = [[NSMutableArray alloc]init];
else
db = array;
}
return self;
}
-(void)addUser:(NSString *)string
{
[db addObject:string];
}
-(void)addUser:(NSString *)string atIndex:(NSInteger)index
{
[db insertObject:string atIndex:index];
}
-(NSString *)getUser:(NSInteger)index
{
return [db objectAtIndex:index];
}
-(void)removeUser:(NSInteger)index
{
[db removeObjectAtIndex:index];
}
-(NSMutableArray *)getDB
{
return db;
}
-(NSInteger)count
{
return [db count];
}
-(void)savePlist:(NSMutableArray *)array
{
NSString *plistPath = [[NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"database.plist"];
NSString *error = nil;
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:array format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
if(plistData)
[plistData writeToFile:plistPath atomically:YES];
}
-(void)saveBinary:(NSMutableArray *)array
{
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"database.db"];
[NSKeyedArchiver archiveRootObject:array toFile:path];
}
@end