這是我希望從中獲得價值的數組的示例。iOS如何從數組中讀取值
coursesArray = [[NSMutableArray alloc]init];
// AR111:
[coursesArray addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:
@"MUR",@"courseType",
@"AR111",@"courseCode",
@"Arabic Communication Skills (I)",@"courseName",
@"3",@"creditHours",
@"",@"preRequisites",
@"63.000",@"coursePrice",
@"6.000",@"courseEPP",
@"This course aims at .",@"courseDetails",
nil]];
這是我的代碼來獲得它的價值。
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
int i = 0;
for (i = 0; i < [coursesArray count] ; i++) {
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
[newManagedObject setValue:[[coursesArray objectAtIndex: i ]forKey:@"courseName"] forKey:@"courseName"];
}
如果任何人能幫助我糾正以下部分:
[newManagedObject setValue:[[coursesArray objectAtIndex: i ]forKey:@"courseName"] forKey:@"courseName"];
的值將在添加到核心數據forKey:@「courseName」。
這是正確的'[newManagedObject setValue:[[coursesArray objectAtIndex:i] objectForKey:@「courseName」] forKey:@「courseName」];' – NamshanNet 2012-08-06 19:42:56
嘗試並重新寫出你寫的內容,使其成爲一個明確的問題。就像「我怎樣才能讀取......並將其設置在...?」 – 2012-08-06 19:58:29