gpt4 book ai didi

ios - 为什么这个获取请求没有返回任何内容

转载 作者:行者123 更新时间:2023-11-29 02:38:56 26 4
gpt4 key购买 nike

我正在尝试过滤一些托管对象。结果虽然是 zip。

过滤器是“名称”。名称是 Root View 向此详细 View 提供的元素。名称记录正常:

[48582:2754928] name: To Be
[48582:2754928] predicate: name == @"name"

name = [self.detailItem valueForKey:@"name"];

NSError *error;
if (![[self fetchedResultsController] performFetch:&error]) {
// Update to handle the error appropriately.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}

FetchResultsController 如下:

 NSError *error = nil;
name = [self.detailItem valueForKey:@"name"];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"VerbEntity" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
predicate = [NSPredicate predicateWithFormat:@"name == %@",@"name"];
NSLog(@"name: %@", name);
fetchRequest.predicate = predicate;
NSLog(@"predicate: %@", predicate);

// Create the sort descriptors array.
NSArray *sortDescriptorArray = nil;

// Declare sort descriptors
NSSortDescriptor *sortDescriptorPrimary = nil;




sortDescriptorPrimary = [[NSSortDescriptor alloc] initWithKey:@"position" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];

// Set sort descriptor array
sortDescriptorArray = @[sortDescriptorPrimary];

// Apply sort descriptors to fetch request
[fetchRequest setSortDescriptors:sortDescriptorArray];

NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];

NSLog(@"fetchedObjects count: %lu", (unsigned long)fetchedObjects.count);
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}

有什么特别奇怪的吗?感谢您的帮助。

最佳答案

您的 _fetchedResultsController 似乎没有设置提取请求。也许不仅仅显示了这个代码片段......但这可能有效

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"VerbEntity"];
request.predicate = [NSPredicate predicateWithFormat:@"name == %@",@"name"];

// Note: Sort descriptors available depend on the backing store type.
NSSortDescriptor *sortDescriptorPrimary = [[NSSortDescriptor alloc] initWithKey:@"position"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)];

request.sortDescriptors = @[sortDescriptorPrimary];

// The request needs to be set on the controller.
NSFetchedResultsController *controller =
[[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
// The controller needs to perform the fetch.
[controller performFetch:nil]; // Optionally pass in an NSError.
controller.delegate = self;
_fetchedResultsController = controller;
return controller;

关于ios - 为什么这个获取请求没有返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26019607/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com