놀랍습니다. 아무도 관심을 보이지 않습니다. 나는 동적으로 생성 된 많은 resultsControllers를 다루는 모든 사람들이 이것을 필요로 할 것이라고 추측했을 것입니다!
// NSFetchedResultsController+GenericCache
- (id)initWithFetchRequest:(NSFetchRequest *)fetchRequest
managedObjectContext:(NSManagedObjectContext *)context
sectionNameKeyPath:(NSString *)sectionNameKeyPath
useCache:(BOOL)useCache {
NSString *cacheId = nil;
if (useCache) {
cacheId = [NSString stringWithFormat:@"%@-%@-%@"
, sectionNameKeyPath
, [fetchRequest entityName]
, [[fetchRequest predicate] predicateFormat]];
for (NSSortDescriptor *descriptor in [fetchRequest sortDescriptors]) {
NSString *sortId = [NSString stringWithFormat:@"-%@-%@-%@"
, [descriptor key]
, ([descriptor ascending]) ? @"ascending": @"descending"
, NSStringFromSelector([descriptor selector])];
cacheId = [cacheId stringByAppendingString:sortId];
}
}
return [self initWithFetchRequest:fetchRequest
managedObjectContext:context
sectionNameKeyPath:sectionNameKeyPath
cacheName:cacheId];
}
- (void)deleteCache {
[[self class] deleteCacheWithName:[self cacheName]];
}
난 아직도 테스트하고 내가 개선을위한 & 제안을 비판하는 것은 매우 개방 이니
어쨌든, 여기 내 솔루션입니다.
신뢰할 수 있도록 도와주세요.