@@ -66,7 +66,7 @@ - (NSInteger)rowid
66
66
return [objc_getAssociatedObject (self , &LKModelBase_Key_RowID) integerValue ];
67
67
}
68
68
69
- - (void )setDb_tableName : (NSString *)db_tableName
69
+ - (void )setDb_tableName : (NSString *)db_tableName
70
70
{
71
71
objc_setAssociatedObject (self, &LKModelBase_Key_TableName, db_tableName, OBJC_ASSOCIATION_COPY_NONATOMIC );
72
72
}
@@ -91,12 +91,12 @@ - (void)setDb_inserting:(BOOL)db_inserting
91
91
objc_setAssociatedObject (self, &LKModelBase_Key_Inserting, number, OBJC_ASSOCIATION_RETAIN_NONATOMIC );
92
92
}
93
93
#pragma 无关紧要的
94
- + (NSString *)getDBImagePathWithName : (NSString *)filename
94
+ + (NSString *)getDBImagePathWithName : (NSString *)filename
95
95
{
96
96
NSString * dir = [NSString stringWithFormat: @" dbimg/%@ " , NSStringFromClass (self )];
97
97
return [LKDBUtils getPathForDocuments: filename inDir: dir];
98
98
}
99
- + (NSString *)getDBDataPathWithName : (NSString *)filename
99
+ + (NSString *)getDBDataPathWithName : (NSString *)filename
100
100
{
101
101
NSString * dir = [NSString stringWithFormat: @" dbdata/%@ " , NSStringFromClass (self )];
102
102
return [LKDBUtils getPathForDocuments: filename inDir: dir];
@@ -112,7 +112,7 @@ + (NSDateFormatter*)getModelDateFormatter
112
112
}
113
113
114
114
// /get
115
- - (id )modelGetValue : (LKDBProperty*)property
115
+ - (id )modelGetValue : (LKDBProperty *)property
116
116
{
117
117
id value = [self valueForKey: property.propertyName];
118
118
id returnValue = value;
@@ -180,8 +180,8 @@ - (id)modelGetValue:(LKDBProperty*)property
180
180
NSData * datas = UIImageJPEGRepresentation (value, 1 );
181
181
#else
182
182
[value lockFocus ];
183
- NSBitmapImageRep * srcImageRep = [NSBitmapImageRep imageRepWithData: [value TIFFRepresentation ]];
184
- NSData * datas = [srcImageRep representationUsingType: NSJPEGFileType properties: @{}];
183
+ NSBitmapImageRep * srcImageRep = [NSBitmapImageRep imageRepWithData: [value TIFFRepresentation ]];
184
+ NSData * datas = [srcImageRep representationUsingType: NSJPEGFileType properties: @{}];
185
185
[value unlockFocus ];
186
186
#endif
187
187
[datas writeToFile: [self .class getDBImagePathWithName: filename]
@@ -192,12 +192,15 @@ - (id)modelGetValue:(LKDBProperty*)property
192
192
else if ([value isKindOfClass: [NSData class ]]) {
193
193
long random = arc4random ();
194
194
long date = [[NSDate date ] timeIntervalSince1970 ];
195
- NSString * filename = [NSString stringWithFormat: @" data%ld%ld " , date & 0xFFFFF , random & 0xFFF ];
195
+ NSString * filename = [NSString stringWithFormat: @" data%ld%ld " , date & 0xFFFFF , random & 0xFFF ];
196
196
197
197
[value writeToFile: [self .class getDBDataPathWithName: filename] atomically: YES ];
198
198
199
199
returnValue = filename;
200
200
}
201
+ else if ([value isKindOfClass: [NSURL class ]]) {
202
+ returnValue = [value absoluteString ];
203
+ }
201
204
else {
202
205
if ([value isKindOfClass: [NSArray class ]]) {
203
206
returnValue = [self db_jsonObjectFromArray: value];
@@ -215,7 +218,7 @@ - (id)modelGetValue:(LKDBProperty*)property
215
218
}
216
219
217
220
// /set
218
- - (void )modelSetValue : (LKDBProperty*)property value : (id )value
221
+ - (void )modelSetValue : (LKDBProperty *)property value : (NSString * )value
219
222
{
220
223
// /参试获取属性的Class
221
224
Class columnClass = NSClassFromString (property.propertyType );
@@ -224,8 +227,7 @@ - (void)modelSetValue:(LKDBProperty*)property value:(id)value
224
227
225
228
if (columnClass == nil ) {
226
229
// /当找不到 class 时,就是 基础类型 int,float CGRect 之类的
227
-
228
- NSString * columnType = property.propertyType ;
230
+ NSString *columnType = property.propertyType ;
229
231
if ([LKSQL_Convert_FloatType rangeOfString: columnType].location != NSNotFound ) {
230
232
modelValue = [[LKDBUtils numberFormatter ] numberFromString: value];
231
233
}
@@ -272,7 +274,7 @@ - (void)modelSetValue:(LKDBProperty*)property value:(id)value
272
274
modelValue = [NSNumber numberWithInt: 0 ];
273
275
}
274
276
}
275
- else if ([value length ] == 0 ) {
277
+ else if (!value || ! [value isKindOfClass: [ NSString class ]] || ![value length ] ) {
276
278
// 为了不继续遍历
277
279
}
278
280
else if ([columnClass isSubclassOfClass: [NSString class ]]) {
@@ -292,41 +294,37 @@ - (void)modelSetValue:(LKDBProperty*)property value:(id)value
292
294
}
293
295
}
294
296
else if ([columnClass isSubclassOfClass: [LKDBColor class ]]) {
295
- NSString * color = value;
296
- NSArray * array = [color componentsSeparatedByString: @" ," ];
297
+ NSString *colorString = value;
298
+ NSArray * array = [colorString componentsSeparatedByString: @" ," ];
297
299
float r, g, b, a;
298
300
r = [[array objectAtIndex: 0 ] floatValue ];
299
301
g = [[array objectAtIndex: 1 ] floatValue ];
300
302
b = [[array objectAtIndex: 2 ] floatValue ];
301
303
a = [[array objectAtIndex: 3 ] floatValue ];
302
-
304
+
303
305
modelValue = [LKDBColor colorWithRed: r green: g blue: b alpha: a];
304
306
}
305
307
else if ([columnClass isSubclassOfClass: [LKDBImage class ]]) {
306
- NSString * filename = value;
307
- NSString * filepath = [self .class getDBImagePathWithName: filename];
308
+ NSString * filename = value;
309
+ NSString * filepath = [self .class getDBImagePathWithName: filename];
308
310
if ([LKDBUtils isFileExists: filepath]) {
309
- LKDBImage* img = [[LKDBImage alloc ] initWithContentsOfFile: filepath];
310
- modelValue = img;
311
- }
312
- else {
313
- modelValue = nil ;
311
+ modelValue = [[LKDBImage alloc ] initWithContentsOfFile: filepath];
314
312
}
315
313
}
316
314
else if ([columnClass isSubclassOfClass: [NSData class ]]) {
317
- NSString * filename = value;
318
- NSString * filepath = [self .class getDBDataPathWithName: filename];
315
+ NSString * filename = value;
316
+ NSString * filepath = [self .class getDBDataPathWithName: filename];
319
317
if ([LKDBUtils isFileExists: filepath]) {
320
- NSData * data = [NSData dataWithContentsOfFile: filepath];
321
- modelValue = data;
322
- }
323
- else {
324
- modelValue = nil ;
318
+ modelValue = [NSData dataWithContentsOfFile: filepath];
325
319
}
326
320
}
321
+ else if ([columnClass isSubclassOfClass: [NSURL class ]]) {
322
+ NSString *urlString = value;
323
+ modelValue = [NSURL URLWithString: urlString];
324
+ }
327
325
else {
328
326
modelValue = [self db_modelWithJsonValue: value];
329
- if ([modelValue isKindOfClass: columnClass] == NO ) {
327
+ if (! [modelValue isKindOfClass: columnClass]) {
330
328
modelValue = nil ;
331
329
}
332
330
}
0 commit comments