2012-01-09 44 views
0

コアデータでデータを読み込む方法を理解するのに困っています。コアデータiPhone - 文字列を読み込む

エンティティ 'People' 'firstName'(文字列)、 'lastName'(文字列)、 'isSpecial'(ブール値)、 'isVerySpecial'(ブール値)というこのエンティティの属性。

私は特別なまたは非常に特別な人物の名字を取得したいので、それらの名前をラベルに入れて、私が好きなところでも好きなところに置くことができます。私は運がなければフェッチリクエストで演奏しました。

ご協力いただきありがとうございます。

self.fetchedResultsController = [Person fetchAllSortedBy:@"lastName" ascending:YES withPredicate:[NSPredicate predicateWithFormat:@"isSpecial == %@ OR isVerySpecial == %@", [NSNumber numberWithBool:YES], [NSNumber numberWithBool:YES]] groupBy:nil delegate:self]; 

、あなたはあなたのfetchedResultsController内の人物の配列を取得します:そのような

答えて

2

何かがそれを行う必要がありホープ:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
NSEntityDescription *weightEntity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:[[yourCoreDataManager sharedInstance] managedObjectContext]]; 
[fetchRequest setEntity:weightEntity]; 
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"isSpecial == %@ OR isVerySpecial == %@", [NSNumber numberWithBool:YES], [NSNumber numberWithBool:YES]]]; 

NSError *error = nil; 
NSArray *result = [[yourCoreDataManager sharedInstance] managedObjectContext] executeFetchRequest:fetchRequest error:&error]; 

そして:

Person *person = [result objectAtIndex:0]; 
NSString *lastName = person.lastName; 
NSString *firstName = person.firstName; 
0

何かがトリックを行う必要があります。それを簡単な使用を取得するには

NSMutableArray *yourArray = [NSMutableArray arrayWithArray: self.fetchedResultsController.fetchedObjects]; 

は、このような

関連する問題