forked from schcat/NMTel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBNRItemStore2.m
More file actions
83 lines (72 loc) · 1.87 KB
/
Copy pathBNRItemStore2.m
File metadata and controls
83 lines (72 loc) · 1.87 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
//
// BNRItemStore2.m
// 0526NMTel
//
// Created by Zhixue Li on 6/2/15.
// Copyright (c) 2015 Zhixue Li. All rights reserved.
//
#import "BNRItemStore2.h"
#import "BNRItem.h"
@interface BNRItemStore2()
@property (nonatomic) NSMutableArray *privateItems;
@end
@implementation BNRItemStore2
+ (instancetype)sharedStore
{
static BNRItemStore2 *sharedStore = nil;
if (!sharedStore) {
sharedStore = [[self alloc] initPrivate];
}
return sharedStore;
}
- (instancetype)init
{
@throw [NSException exceptionWithName:@"Singleton"
reason:@"Use +[BNRItemStore sharedStore]"
userInfo:nil];
return nil;
}
- (instancetype)initPrivate
{
self = [super init];
if (self) {
_privateItems = [[NSMutableArray alloc] init];
}
return self;
}
- (NSArray *)allItems
{
return self.privateItems;
// return [self.privateItems copy];
}
- (BNRItem *)createItem
{
BNRItem *item = [BNRItem initItem];
[self.privateItems addObject:item];
return item;
}
-(void)removeItem:(BNRItem *)item
{
[self.privateItems removeObjectIdenticalTo:item];
}
- (void)moveItemAtIndex:(NSUInteger)fromIndex
toIndex:(NSUInteger)toIndex
{
if (fromIndex == toIndex) {
return;
}
BNRItem *item = self.privateItems[fromIndex];
[self.privateItems removeObjectAtIndex:fromIndex];
[self.privateItems insertObject:item atIndex:toIndex];
}
- (BNRItem *)createContacts
{
BNRItem *item1 = [[BNRItem alloc] initWithItemName:@"联系人姓名"
NMTelCellPhone:@"联系人手机号"
NMTelLandLine:@"联系人分机号"
NMTelContactEmail:@"联系人邮箱地址"];
[self.privateItems addObject:item1];
//重复多个
return item1;
}
@end