在Xcode中从核心数据填充数组 [英] Populating an Array from Core Data in Xcode
本文介绍了在Xcode中从核心数据填充数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用从CoreData获取的数据集合填充 NSArray 。但我的数组似乎没有填充数据。我有以下代码检索数据:
I am trying to populate an NSArray with a collection of data I get from CoreData. But my array doesnt seem to be populating with the data. I have the following code to retrieve the data:
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]
initWithEntityName:@"WeightLog"];
self.contactarray = [[managedObjectContext executeFetchRequest:fetchRequest
error:nil] mutableCopy];
并且我使用下面的for循环来填充NSArray与我从WeightLog收集的数据a特定字段。
And I am using the following for loop to populate the NSArray with the data I collect from WeightLog for a particular field.
for (int i =0; i<=self.contactarray.count; i++) {
NSManagedObject *device = [self.contactarray objectAtIndex:i];
[titleNames addObject:device];
}
只是因为您知道 contactarray 我的.h文件格式如下:
Just so you know contactarray is a property in my .h file of the following format:
@property (strong) NSMutableArray *contactarray;
你能告诉我哪里出错了,我是iOS开发的新手
Can you tell me where I am going wrong please, I am fairly new to iOS Development, if it doesn't show.
提前感谢您
推荐答案
titleNames
数组。试试这个,
titleNames = [[NSMutableArray alloc] init];
for (int i =0; i<=self.contactarray.count; i++) {
NSManagedObject *device = [self.contactarray objectAtIndex:i];
[titleNames addObject:device];
}
这篇关于在Xcode中从核心数据填充数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文