ios - CoreData 相关问题?
<p><p>我有一个与 <strong>CoreData</strong> 相关的问题,</p>
<p>我有这个 .xcdatamodeld 文件,它有 2 个实体,<em>RCHTask</em> 和 <em>RCHTaskType</em></p>
<p> <a href="/image/cAz3Q.png" rel="noreferrer noopener nofollow"><img src="/image/cAz3Q.png" alt="RCHTask"/></a>
<a href="/image/YUtWo.png" rel="noreferrer noopener nofollow"><img src="/image/YUtWo.png" alt="RCHTaskType"/></a> </p>
<p>RCHTask 与 RCHTaskType 有<strong>多对一</strong>关系</p>
<p>RCHTaskType 与 RCHTask 有<strong>一对多</strong>关系</p>
<p>我正在尝试获取具有特定 taskType 的 RCHTask 实例
但我失败了,我试过这个:</p>
<pre><code>- (NSArray *)returnTaskOfType:(NSString *)type
{
NSFetchRequest *request = [ init];
NSEntityDescription *e = [NSEntityDescription entityForName:@"RCHTask"
inManagedObjectContext:self.context];
request.entity = e;
NSPredicate *predicate = ;
request.predicate = predicate;
NSError *error = nil;
NSArray *result = [self.context executeFetchRequest:request
error:&error];
return result;
}
</code></pre>
<p>但是不工作你能告诉我怎么做吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您必须使用关系的名称。然后修改您的代码以获取任务,并使用关系名称指定谓词:</p>
<pre><code>- (NSArray *)returnTaskOfType:(NSString *)type
{
NSFetchRequest *request = [ init];
NSEntityDescription *e = [NSEntityDescription entityForName:@"RCHTask"
inManagedObjectContext:self.context];
request.entity = e;
NSPredicate *predicate = ;
request.predicate = predicate;
NSError *error = nil;
NSArray *result = [self.context executeFetchRequest:request
error:&error];
return result;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - CoreData 相关问题?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31664641/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31664641/
</a>
</p>
页:
[1]