我已經從我的應用程序的核心數據中獲取了一個結果,並且需要獲取我賦予其「容量」屬性的整數值。從CoreData獲取整數?
'容量'屬性是我的核心數據模型中的NSInteger 16。
我得到我的結果,像這樣:
entity = [NSEntityDescription entityForName:@"TableInfo" inManagedObjectContext:appDelegate.managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"name == %@", [NSString stringWithFormat:@"%@", [tablesArray objectAtIndex:row]]]];
NSArray *selectedTableFetched = [appDelegate.managedObjectContext executeFetchRequest:fetchRequest error:&error];
現在我的問題是我如何才能從我的結果,「能力」的價值?我知道有,因爲我有檢查數組的計數結果,我已經試過這樣:
NSNumber *n = [selectedTableFetched valueForKey:@"capacity"];
它給我的東西,在訪問的NSNumber時,我得到一個毫無意義的長號碼,因此,如果我嘗試訪問整數值,像這樣:
[n integerValue]
崩潰的應用程序,我得到這個錯誤:
'NSInvalidArgumentException', reason: '-[__NSArrayI integerValue]: unrecognized selector sent to instance 0x138870'
希望你能幫助我,我需要做的是從容量attribu獲取整數值泰,謝謝。
我認爲'[selectedTableFetched valueForKey:@ 「能力」]'不返回'NSNumber'而是'NSArray' – tipycalFlow 2012-03-25 18:11:05