Xcode 4:提取请求模板变量? [英] Xcode 4: Fetch Request Template Variables?
问题描述
在Xcode 3.X中,您应该右键点击抓取请求模板的谓词编辑器中的空格,以指定一个变量输入而不是硬编码谓词。
In Xcode 3.X, you were supposed to right-click the whitespace in the fetch request template's predicate editor to specify a variable input rather than a hard-coded predicate.
在XCode 4中这是什么?我拿着选项,右键点击,选项点击等等,不能弄清楚....
Where is this in XCode 4? I've held option, right-clicked, option-clicked, etc and cannot figure it out....
推荐答案
t认为X4有变量了。
I don't think X4 has the variable anymore.
相反,我认为你必须选择一个表达式,然后提供一个 $ VARNAME
形式的变量。
Instead, I think you have to choose an expression and then provide a variable of the form $VARNAME
.
例如,给定实体 Alpha
,其属性为 aString
,我创建了一个获取请求模板 bobFetch
,其表达式为 aString == $ TESTVAR
。
For example, given and entity Alpha
with an attribute aString
, I created a fetch request template bobFetch
with an expression of aString == $TESTVAR
.
Alpha *a=[NSEntityDescription insertNewObjectForEntityForName:@"Alpha" inManagedObjectContext:self.moc];
a.aString=@"steve";
[self saveContext];
NSDictionary *subVars=[NSDictionary dictionaryWithObject:@"steve" forKey:@"TESTVAR"];
NSFetchRequest *fetchRequest = [self.managedObjectModel fetchRequestFromTemplateWithName:@"bobRequest" substitutionVariables:subVars];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Alpha" inManagedObjectContext:self.moc];
[fetchRequest setEntity:entity];
如果记录 fetchRequest
reports:
If logged fetchRequest
reports:
<NSFetchRequest: 0x4d17480> (entity: Alpha; predicate: (aString == "steve"); sortDescriptors: ((null)); type: NSManagedObjectResultType; )
$ b b
...然后可以正常使用。
... and can then be used normally.
NSError *error = nil;
NSArray *fetchedObjects = [self.moc executeFetchRequest:fetchRequest error:&error];
if (fetchedObjects == nil) {
NSLog(@"fetch error = %@",error);
}
NSLog(@"fetchObjects = %@",fetchedObjects);
图形环境的笨拙的种类,但它工作。
Kind of clumsy for a graphical environment but it works.
这篇关于Xcode 4:提取请求模板变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!