User Defaults

读取

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
读取object值(不推荐)

@param key 键
@return 值
*/
+ (nullable id)ax_readObjectForKey:(NSString *)key;

/**
读取object值(推荐)

@param key 键
@param completion 读取成功
@param failure 读取失败(没有值)
*/
+ (void)ax_readObjectForKey:(NSString *)key completion:(void (^)(id object))completion failure:(void (^)(NSError *error))failure;

/**
读取BOOL值

@param key 键
@return 值
*/
+ (BOOL)ax_readBoolForKey:(NSString *)key;

/**
读取NSInteger值

@param key 键
@return 值
*/
+ (NSInteger)ax_readIntegerForKey:(NSString *)key;

/**
读取float值

@param key 键
@return 值
*/
+ (float)ax_readFloatForKey:(NSString *)key;

/**
读取double值

@param key 键
@return 值
*/
+ (double)ax_readDoubleForKey:(NSString *)key;

/**
读取CGFloat值

@param key 键
@return 值
*/
+ (CGFloat)ax_readCGFloatForKey:(NSString *)key;


/**
读取NSData值(不推荐)

@param key 键
@return 值
*/
+ (nullable NSData *)ax_readDataForKey:(NSString *)key;

/**
读取NSData值(推荐)

@param key 键
@param completion 读取成功
@param failure 读取失败(没有值)
*/
+ (void)ax_readDataForKey:(NSString *)key completion:(void (^)(NSData *data))completion failure:(void (^)(NSError *error))failure;

/**
读取NSString值(不推荐)

@param key 键
@return 值
*/
+ (nullable NSString *)ax_readStringForKey:(NSString *)key;

/**
读取NSString值(推荐)

@param key 键
@param completion 读取成功
@param failure 读取失败(没有值)
*/
+ (void)ax_readStringForKey:(NSString *)key completion:(void (^)(NSString *string))completion failure:(void (^)(NSError *error))failure;

/**
读取字符串数组(不推荐)

@param key 键
@return 值
*/
+ (nullable NSArray<NSString *> *)ax_readStringArrayForKey:(NSString *)key;

/**
读取字符串数组(推荐)

@param key 键
@param completion 读取成功
@param failure 读取失败(没有值)
*/
+ (void)ax_readStringArrayForKey:(NSString *)key completion:(void (^)(NSArray<NSString *> *array))completion failure:(void (^)(NSError *error))failure;

/**
读取NSArray值(不推荐)

@param key 键
@return 值
*/
+ (nullable NSArray *)ax_readArrayForKey:(NSString *)key;

/**
读取NSArray值(推荐)

@param key 键
@param completion 读取成功
@param failure 读取失败(没有值)
*/
+ (void)ax_readArrayForKey:(NSString *)key completion:(void (^)(NSArray *array))completion failure:(void (^)(NSError *error))failure;

/**
读取NSDictionary值(不推荐)

@param key 键
@return 值
*/
+ (nullable NSDictionary<NSString *, id> *)ax_readDictionaryForKey:(NSString *)key;

/**
读取NSDictionary值(推荐)

@param key 键
@param completion 读取成功
@param failure 读取失败(没有值)
*/
+ (void)ax_readDictionaryForKey:(NSString *)key completion:(void (^)(NSDictionary *dictionary))completion failure:(void (^)(NSError *error))failure;

/**
读取若干字符串值,并组装成NSDictionary

@param keys 键
@return 值
*/
+ (NSDictionary<NSString *, id> *)ax_readDictionaryWithValuesForKeys:(NSArray<NSString *> *)keys;

/**
读取URL值(不推荐)

@param key 键
@return 值
*/
+ (nullable NSURL *)ax_readURLForKey:(NSString *)key;

/**
读取NSURL值(推荐)

@param key 键
@param completion 读取成功
@param failure 读取失败(没有值)
*/
+ (void)ax_readURLForKey:(NSString *)key completion:(void (^)(NSURL *url))completion failure:(void (^)(NSError *error))failure;


/**
读取图片(不推荐)

@param key 键
@return 值
*/
+ (nullable UIImage *)ax_readImageForKey:(NSString *)key;

/**
读取图片(推荐)

@param key 键
@param completion 读取成功
@param failure 读取失败(没有值)
*/
+ (void)ax_readImageForKey:(NSString *)key completion:(void (^)(UIImage *image))completion failure:(void (^)(NSError *error))failure;

写入

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

/**
批量保存用户设置,自带synchronize

@param action 批量保存用户设置的block
*/
+ (void)ax_caches:(void (^)(NSUserDefaults *defaultUser))action;

/**
保存id对象,自带synchronize

@param obj 值
@param key 键
*/
+ (void)ax_setObject:(nullable id)obj forKey:(NSString *)key;

/**
保存value,自带synchronize

@param value 值
@param key 键
*/
+ (void)ax_setValue:(nullable id)value forKey:(NSString *)key;

/**
保存BOOL值,自带synchronize

@param x 值
@param key 键
*/
+ (void)ax_setBool:(BOOL)x forKey:(NSString *)key;

/**
保存NSInteger,自带synchronize

@param x 值
@param key 键
*/
+ (void)ax_setInteger:(NSInteger)x forKey:(NSString *)key;

/**
保存float,自带synchronize

@param x 值
@param key 键
*/
+ (void)ax_setFloat:(float)x forKey:(NSString *)key;

/**
保存double,自带synchronize

@param x 值
@param key 键
*/
+ (void)ax_setDouble:(double)x forKey:(NSString *)key;

/**
保存CGFloat,自带synchronize

@param x 值
@param key 键
*/
+ (void)ax_setCGFloat:(CGFloat)x forKey:(NSString *)key;

/**
保存NSData,自带synchronize

@param data 值
@param key 键
*/
+ (void)ax_setData:(nullable NSData *)data forKey:(NSString *)key;

/**
保存字符串,自带synchronize

@param string 值
@param key 键
*/
+ (void)ax_setString:(nullable NSString *)string forKey:(NSString *)key;

/**
保存字符串数组,自带synchronize

@param block 值
@param key 键
*/
+ (void)ax_setStringArray:(NSArray *(^)(NSArray<NSString *> *cachedArray))block forKey:(NSString *)key;

/**
保存数组,自带synchronize

@param block 值
@param key 键
*/
+ (void)ax_setArray:(nullable NSArray *(^)(NSArray *cachedArray))block forKey:(NSString *)key;

/**
保存字典,自带synchronize

@param block 值
@param key 键
*/
+ (void)ax_setDictionary:(NSDictionary *(^)(NSMutableDictionary <NSString *, id> * dict))block forKey:(NSString *)key;
/**
保存NSURL,自带synchronize

@param url 值
@param key 键
*/
+ (void)ax_setURL:(nullable NSURL *)url forKey:(NSString *)key;


/**
保存图片,自带synchronize

@param image 图片
@param key 键
*/
+ (void)ax_setImage:(nullable UIImage *)image forKey:(NSString *)key;


/**
批量保存用户设置,自带synchronize

@param action 批量保存用户设置的block
*/
- (void)ax_caches:(void (^)(NSUserDefaults *user))action;

/**
保存NSData,不带synchronize

@param data 值
@param key 键
*/
- (void)ax_setData:(nullable NSData *)data forKey:(NSString *)key;

/**
保存字符串,不带synchronize

@param string 值
@param key 键
*/
- (void)ax_setString:(nullable NSString *)string forKey:(NSString *)key;

/**
保存字符串数组,不带synchronize

@param block 值
@param key 键
*/
- (void)ax_setStringArray:(NSArray *(^)(NSArray<NSString *> *cachedArray))block forKey:(NSString *)key;

/**
保存数组,不带synchronize

@param block 值
@param key 键
*/
- (void)ax_setArray:(nullable NSArray *(^)(NSArray *cachedArray))block forKey:(NSString *)key;

/**
保存字典,不带synchronize

@param block 值
@param key 键
*/
- (void)ax_setDictionary:(NSDictionary *(^)(NSMutableDictionary <NSString *, id> * dict))block forKey:(NSString *)key;

/**
保存NSURL,不带synchronize

@param url 值
@param key 键
*/
- (void)ax_setURL:(nullable NSURL *)url forKey:(NSString *)key;

删除

1
2
3
4
5
6
7
8
9
10
11
12
/**
删除用户设置,自带synchronize

@param key 键
*/
+ (void)ax_removeObjectForKey:(NSString *)key;


/**
移除默认的[NSUserDefaults standardUserDefaults]的所有配置
*/
+ (void)ax_removeDefaultPersistentDomain;



评论

有疑问请前往本项目的【Issue】页面搜索问题,如果没有相关问题,点击【New issue】进行提问。