0

アプリケーションでcoredataを使用して値を格納および取得しています。NSMutableArrayを使用したいのですが、

AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"NewExpense" inManagedObjectContext:context];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
[fetchRequest setEntity:entityDesc];
NSError *error;

//self.newArrayがNSMutableArrayである次の行でエラーが発生します

self.newArray = [[context executeFetchRequest:fetchRequest error:&error]retain];
[fetchRequest release];

nsarrayからnsmutablearrayに割り当てる互換性のないポインタ型を示しています。

しかし、テーブルビューを編集しているときに、それを単なる配列として宣言すると、nsmutablearrayが必要になるため、並べ替えが機能しません。

4

2 に答える 2

0

これを行う:

 self.newArray = [[context executeFetchRequest:fetchRequest error:&error]mutableCopy]

お役に立てば幸いです。

于 2012-06-12T06:41:30.813 に答える
0

これは、executeFetch が不変の配列を返すためです。

使用する:[NSMutableArray arrayWithArray:...];

于 2012-06-12T06:42:09.750 に答える