BUPersistence.h
1.4 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
//
// BUPersistence.h
// BUPersistence
//
// Created by Chen Hong on 2017/1/10.
// Copyright © 2017年 Chen Hong. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, BUPersistentType) {
BUPersistentTypePlist,
BUPersistentTypeKeyChain,
BUPersistentTypeCustom,
};
@interface BUPersistenceOption : NSObject
@property (nonatomic) BUPersistentType type;
@property (nonatomic) BOOL shouldRemoveAllObjectsOnMemoryWarning;
@property (nonatomic) BOOL shouldRemoveAllObjectsWhenEnteringBackground;
@property (nonatomic) BOOL supportNSCoding;
@end
@protocol BUPersistenceProtocol <NSObject>
- (NSArray *)allObjects;
- (nullable id)objectForKey:(NSString *)key;
- (nullable NSArray *)objectsForKeys:(NSArray *)keys;
- (void)updateObjectsForKeys:(NSArray *)keys WithBlock:(NSDictionary * (^)(NSArray *objects))block;
- (BOOL)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key;
- (BOOL)hasObjectForKey:(NSString *)key;
- (BOOL)removeAll;
- (BOOL)removeObjectsForKeys:(NSArray<NSString *> *)keys;
- (BOOL)save;
@end
@interface BUPersistence : NSObject <BUPersistenceProtocol>
+ (nullable instancetype)persistenceWithName:(NSString *)name;
+ (nullable instancetype)persistenceWithName:(NSString *)name option:(BUPersistenceOption *)option;
+ (void)deleteWithName:(NSString *)name;
+ (NSString *)cacheDirectory;
@end
NS_ASSUME_NONNULL_END