我想爲iPhone開發一個應用程序使用核心數據,我用一個非常基本的謂詞來抓取對象。 (即attribute_name ==字符串)無法爲謂詞生成SQL(_STRING PREDICATE_)(RHS上的問題)是什麼意思?
我檢查了模型,以確保屬性名稱是正確的,我知道從this SO question RHS的意思是「右手邊」,這導致我「串」部分。我創建使用
NSString *predicateString = [NSString stringWithFormat:@"attribute_name==%@", string];
然後獲取格式字符串,我使用的是這樣的:
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:_entityName inManagedObjectContext:managedObjectContext];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateString];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *array = [managedObjectContext executeFetchRequest:request error:&error];
我缺少什麼?什麼可能導致這個錯誤發生?
謝謝。
你的字符串包含什麼? – bbum
該字符串包含使用快速枚舉擴展的數組中的另一個字符串對象。因此它看起來像這樣:for(NSString * stringInArray in array){NSString * predicateString = [NSString stringWithFormat:@「attribute_name ==%@」,stringInArray]; }'感謝@ bbum的快速響應! –