Objective c FilteredarrayingPredicate始终返回nil NSArray?
我使用CoreData获取了一些项目,我想使用filteredArrayUsingPredicate过滤这些结果,这给了我一些问题 CoreData获取:Objective c FilteredarrayingPredicate始终返回nil NSArray?,objective-c,ios,core-data,Objective C,Ios,Core Data,我使用CoreData获取了一些项目,我想使用filteredArrayUsingPredicate过滤这些结果,这给了我一些问题 CoreData获取: NSFetchRequest *request = [[NSFetchRequest alloc]init]; [request setEntity:[NSEntityDescription entityForName:@"Collection" inManagedObjectContext:aContext]]; NSPredicate *
NSFetchRequest *request = [[NSFetchRequest alloc]init];
[request setEntity:[NSEntityDescription entityForName:@"Collection" inManagedObjectContext:aContext]];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"CategoryName==%@", aCategoryName];
[request setPredicate:pred];
NSError *error=nil;
NSArray *tempArray=[aContext executeFetchRequest:request error:&error];
[request release], request = nil;
NSLog(@"results: %@", tempArray);
这给了我这个结果:
results: (
"<Collection: 0x8eb1920> (entity: Collection; id: 0x8eb0aa0 <x-coredata://7C4A4A5D-691A-4F02-9450-D0D910B53903/Collection/p95> ; data: {\n CategoryID = 22832;\n CategoryName = \"2000 - NOURISON 2000\";\n IsDeleted = 0;\n ManufacturerID = 192;\n ModifiedOn = \"2012-03-08 09:00:46 +0000\";\n ParentCategoryID = 0;\n PhotoName = \"\";\n SortOrder = 0;\n})"
)
result: (null)
这给了我这个结果:
results: (
"<Collection: 0x8eb1920> (entity: Collection; id: 0x8eb0aa0 <x-coredata://7C4A4A5D-691A-4F02-9450-D0D910B53903/Collection/p95> ; data: {\n CategoryID = 22832;\n CategoryName = \"2000 - NOURISON 2000\";\n IsDeleted = 0;\n ManufacturerID = 192;\n ModifiedOn = \"2012-03-08 09:00:46 +0000\";\n ParentCategoryID = 0;\n PhotoName = \"\";\n SortOrder = 0;\n})"
)
result: (null)
不确定这里缺少了什么,我正在为这个过滤数组谓词传递正确的ManufacturerID of 192。什么是ManufacturerID 通过使用
%@
格式说明符,它很可能是[NSNumber numberwhithint:192]
或者,如果不想用NSNumber
换行,可以将谓词中的格式从%@
更改为%d
NSInteger aManufacturerID = 192;
Collection *collection = [[tempArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"ManufacturerID==%d", aManufacturerID]] lastObject];
NSLog(@"result: %@ " , collection);
什么是
amufacturerid
?很可能是[NSNumber numberWithInt:192]
很奇怪,就是这样-我说奇怪是因为我之前在CoreData获取请求中过滤了这两个参数,并且我不需要将制造商强制转换为NSNumber。我应该试着用那篇文章作为答案,这样我就可以相信你了。