본문 바로가기
프로그래밍 놀이터/iOS

[ios/tutorial] Core Data - Fetching Objects

by 돼지왕 왕돼지 2017. 11. 4.
반응형

 [ios/tutorial] Core Data - Fetching Objects


https://developer.apple.com/library/watchos/documentation/Cocoa/Conceptual/CoreData/FetchingObjects.html#//apple_ref/doc/uid/TP40001075-CH6-SW1


core data, data fetch, error, executeFetchRequest, Fetching NSManagedObject Instances, Fetching Results, fetchRequestWithEnityName, moc, NSFetchRequest, NSPredicate, predicateWithFormat, setPredicate, [ios/tutorial] Core Data - Fetching Objects


-

NSFetchRequest 를 이용해서 존재하는 data 를 fetch 해올 수 있다.



Fetching NSManagedObject Instances


-

NSManagedObjectContext *moc = …;

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEnityName:@“Employee”];


NSError *error = nil;

NSArray* result = [moc executeFetchRequest:request error:&error];

if (!result){

     DLog(@“Error fetching employee objects: %@\n%@“, [error localizedDescription], [error userInfo]);

     abort();

}




Fetching Results


-

NSPredicate 를 이용하면 조건을 걸어서 fetch 를 할 수 있다.

NSString *firstName = @“Trevor”;

[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@“firstName == %@“, firstName]];





반응형

댓글