存储获取数组数据的位置?

时间:2010-09-25 19:58:41

标签: iphone core-data

我尝试[eventArray值]但没有 - 我就是这样 78999 3451237 3451237

但必须 90

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:app.managedObjectContext];   
NSFetchRequest *request = [[NSFetchRequest alloc] init];  
[request setEntity:entity];   
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"values" ascending:NO];  
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];  
[request setSortDescriptors:sortDescriptors];  
[sortDescriptor release];   
NSMutableArray *mutableFetchResults = [[app.managedObjectContext executeFetchRequest:request error:&error] mutableCopy];   
if (!mutableFetchResults) { }    
[self setEventArray: mutableFetchResults];  
event = [eventArray objectAtIndex:3];
NSNumber * info = [event values];
printf("\n%d", [event values]);
[mutableFetchResults release];  
[request release];  

2 个答案:

答案 0 :(得分:0)

if (!mutableFetchResults) { } 

对此的任何解释?

答案 1 :(得分:0)

我假设event变量在这里:

event = [eventArray objectAtIndex:3];

是一个NSManagedObject,其实体具有名为values的数字属性。如果是这样,则[event values]将返回NSNumber实例,而不是int或double。因此,这一行:

printf("\n%d", [event values]);

...不会打印出返回的NSNumber实例的double值,而是打印内存中实例地址的十进制表示。要记录您需要使用的实际值:

printf("\n%d", [[event values] intValue]);