在核心数据获取结果为空时设置默认值

时间:2013-03-31 03:19:16

标签: objective-c

我正在使用简单的核心数据获取请求代码。

- (NSMutableArray *) read_cd
{
    NSError *error = nil;
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"List_CD" inManagedObjectContext:cd_Context];
    [request setEntity:entity];
    NSSortDescriptor *sd = [[NSSortDescriptor alloc] initWithKey:@"last_date" ascending:NO];
    NSArray *sortDescriptor = [[NSArray alloc] initWithObjects:sd, nil];
    [request setSortDescriptors:sortDescriptor];
    NSMutableArray *mutableFetchResults = [[cd_Context executeFetchRequest:request error:&error] mutableCopy];
    if(mutableFetchResults == nil){
        //Handle the error
    }
    return mutableFetchResults;
}

我正在使用像这样的返回值

MSMutableArray *now_cd = self.read_cd;
cell output for {
    cell.label1.text = [[now_cd objectAtIndex:i] cd_title];
    cell.label2.text = [[now_cd objectAtIndex:i] cd_auth];
}

我想在executeFetchRequest为null时设置默认值。 所以我可以继续使用现有的输出模块。

我不知道怎么做这样的方法

[[object objectAtIndex:i] instance]

0 个答案:

没有答案
相关问题