Zepo / GYDataCenter

An alternative to Core Data for people who like using SQLite directly.
MIT License
842 stars 132 forks source link

[cache setValue:value forKey:[propertyClass primaryKey]] value 为 nil 崩溃问题 #35

Open levicc opened 6 years ago

levicc commented 6 years ago
NSDate *date = [NSDate date];
    Employee *employee = [[Employee alloc] initWithId:2
                                                 name:@"New Emp2"
                                          dateOfBirth:date
                                           department:nil];
    [employee save];

像例子那样,存的 department 为 nil,之后取出来会在 300 行处崩溃:

//GYDBRunner.m
if (propertyClass && value) {   //这边加个判断才行
        id cache = [_cacheDelegate objectOfClass:propertyClass id:value];
        if (!cache) {
            cache = [[(Class)propertyClass alloc] init];
            **[cache setValue:value forKey:[propertyClass primaryKey]];**
            [cache setValue:@YES forKey:@"fault"];
            [_cacheDelegate cacheObject:cache];
        }
        value = cache;
    }

按理说肯定会考虑过这个问题,是我的姿势有问题吗?