我有一个奇怪的错误:如果我取消注释 my NSPredicate
,结果UITableView
是空的。
我的数据模型如下:类别 <-->> Feed <-->> Post
我正在取Post
s。Post.feed
是一个Post
。有财产。Feed
Feed
rss
NString
这是代码:
- (NSFetchedResultsController *)fetchedResultsController {
// Set up the fetched results controller if needed.
if (_fetchedResultsController == nil) {
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Post"
inManagedObjectContext:_globalMOC];
[fetchRequest setEntity:entity];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSPredicate *predicate =[NSPredicate predicateWithFormat:@"feed.rss == %@", _detailItem.rss];
[fetchRequest setPredicate:predicate];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:_globalMOC
sectionNameKeyPath:nil
cacheName:nil];
self.fetchedResultsController = aFetchedResultsController;
self.fetchedResultsController.delegate = self;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate.
// You should not use this function in a shipping application, although it may be useful
// during development. If it is not possible to recover from the error, display an alert
// panel that instructs the user to quit the application by pressing the Home button.
//
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
return _fetchedResultsController;
}
正如我之前所说,如果我取消注释,我只会看到结果NSPredicate
。我尝试使用LIKE
, ==
, =
, 用双引号和单引号%@
...
顺便说一句,最好的办法是直接比较Feed
对象......
根据 Apple 的说法,语法可能不是问题,但那又如何呢?
s 在共享相同 PersistentStoreCoordinator的Post
单独 ManagedObjectController 中创建。我得到了所需Feed
的 objectID,以便将新对象Post
与子 MOC 中的对应对象相关联Feed
(否则我会收到关于关联来自不同 MOC 的对象的错误)。
每当子 MOC 通知它发生更改时,我也会适当地将我的 MOC 合并到主线程中。
基本上:如果我NSLog
有Post
(commented-NSPredicate),我会看到每一个都Post
带有适合显示的相关 RSS Feed
URL Feed
(= detailItem
)。
任何人都可以帮助我吗?