Roobiq / RBQFetchedResultsController

Drop-in replacement for NSFetchedResultsController backed by Realm.
MIT License
477 stars 70 forks source link

fetchedResultsController.fetchObjects is not empty, but [FRC objectAtIndexPath:indexPath] return nil? #81

Open zenghaojim33 opened 8 years ago

zenghaojim33 commented 8 years ago

I used this library in my project and it works well on 64bit devices, but this bug happens on iPhone5 and iPhone4s. Basically I just copy codes from the demo project. Any idea what may cause this ? thanks in advance.

bigfish24 commented 8 years ago

I have no idea. Can you run demo project directly?

zenghaojim33 commented 8 years ago

OK I found the solution. In RBQObjectCacheObject.m file

+ (RLMObject *)objectInRealm:(RLMRealm *)realm
              forCacheObject:(RBQObjectCacheObject *)cacheObject
{
    if (cacheObject.primaryKeyType == RLMPropertyTypeString) {

        return [realm objectWithClassName:cacheObject.className forPrimaryKey:cacheObject.primaryKeyStringValue];
    }
    else if (cacheObject.primaryKeyType == RLMPropertyTypeInt) {
        NSNumber *numberFromString = @(cacheObject.primaryKeyStringValue.integerValue);

        return [realm objectWithClassName:cacheObject.className forPrimaryKey:numberFromString];
    }
    else {
        @throw ([self unsupportedPrimaryKeyTypeException]);
    }
}

I change integerValue to LonglongVaue since my primary key number is long long and it's very large so this causes some precision loses.

bigfish24 commented 8 years ago

Ah, nice catch!

bigfish24 commented 8 years ago

@zenghaojim33 can you submit PR with this change?

zenghaojim33 commented 8 years ago

Sure.

tuananh00473 commented 8 years ago

I checked my code in RBQObjectCacheObject.m as longLongValue like here `+ (RLMObject )objectInRealm:(RLMRealm )realm forCacheObject:(RBQObjectCacheObject *)cacheObject { if (cacheObject.primaryKeyType == RLMPropertyTypeString) {

    return [realm objectWithClassName:cacheObject.className forPrimaryKey:cacheObject.primaryKeyStringValue];
}
else if (cacheObject.primaryKeyType == RLMPropertyTypeInt) {
    NSNumber *numberFromString = @(cacheObject.primaryKeyStringValue.longLongValue);

    return [realm objectWithClassName:cacheObject.className forPrimaryKey:numberFromString];
}
else {
    @throw ([self unsupportedPrimaryKeyTypeException]);
}

}`

but i still take this issue. Can you help me!