如何将coredata添加到Array

时间:2015-08-02 15:29:49

标签: ios objective-c arrays core-data

我认为问题在于我的for循环。 数组的计数结果为0.没有添加任何值。

NSLog每次都会输出不同的信息,但数据没有被添加到可变数组中。

NSLog:

  

2015-08-02 11:27:44.326 iOSInterviewPro [46661:1548947]你在哪里可以   如果您没有设备,请测试Apple iPhone应用程序?

     

2015-08-02 11:27:44.326 iOSInterviewPro [46661:1548947]哪个API是   用于编写有助于运行应用程序的测试脚本   用户界面元素?

-(void) getQuiz {
 CoreDataStack *coreDataStack = [CoreDataStack coreDataStack];
// Fetching
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Jsonp"];

// Add Sort Descriptor
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"questions" ascending:YES];
[fetchRequest setSortDescriptors:@[sortDescriptor]];

// Execute Fetch Request
NSError *error = nil;
 NSArray *arr = [[coreDataStack managedObjectContext] executeFetchRequest:fetchRequest error:&error];

if (!error) {
    for (NSManagedObject *managedObject in arr) {
//            [questionsFArray addObject:[managedObject valueForKey:@"questions"]];
        NSLog(@"%@, %@", [managedObject valueForKey:@"questions"]);
        [questionsFArray addObject:[NSString stringWithFormat:@"%@", [managedObject valueForKey:@"questions"]]];


    }

} else {
    NSLog(@"Error fetching data.");
    NSLog(@"%@, %@", error, error.localizedDescription);
}

NSLog(@"Count : %lu", (unsigned long)questionsFArray.count  );

}

0 个答案:

没有答案