hachinoBlog

hachinobuのエンジニアライフ

CoreDataのFrom句Select句

CoreDataのSelectカラム指定方法。

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entitydesc = [coreDataManager entityDescription:@"TableName"]; //from句(テーブル指定)

//ここからカラム指定
NSMutableArray *properties = [NSMutableArray arrayWithObject:[entityProperties objectForKey:@"カラム名"]];
[properties addObject:[entityProperties objectForKey:@"カラム名"]]; //2つ目のカラム名
[fetchRequest setPropertiesToFetch:properties]; //セットした2カラムを抽出するようにセットする

ちなみにNSFetchedResultsControllerを使うとUITableViewの表示がとても楽になる

参考URL
http://blog.natsuapps.com/2010/03/nsfetchedresultscontroller-sectionnamekeypath.html