수색…


소개

Core Data는 가능한 가장 넓은 의미에서 응용 프로그램의 모델 계층입니다. iOS SDK에 스며드는 Model-View-Controller 패턴의 모델입니다.

핵심 데이터는 응용 프로그램의 데이터베이스가 아니며 데이터베이스에 데이터를 유지하기위한 API도 아닙니다. 핵심 데이터는 객체 그래프를 관리하는 프레임 워크입니다. 그것만큼이나 간단합니다. 핵심 데이터는 객체 그래프를 디스크에 기록하여 유지할 수 있지만 프레임 워크의 주요 목표는 아닙니다.

핵심 데이터 작업

컨텍스트를 얻으려면 :

NSManagedObjectContext *context = ((AppDelegate*)[[UIApplication sharedApplication] delegate]).persistentContainer.viewContext;

데이터 가져 오기 :

NSFetchRequest<EntityName *> *fetchRequest = [EntityName fetchRequest];
NSError *error ;
NSArray *resultArray= [context executeFetchRequest:fetchRequest error:&error];

정렬을 사용하여 데이터를 가져 오려면 다음을 수행하십시오.

NSFetchRequest<EntityName *> *fetchRequest = [EntityName fetchRequest];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"someKey" ascending:YES];
fetchRequest.sortDescriptors = @[sortDescriptor];
NSError *error ;
NSArray *resultArray= [context executeFetchRequest:fetchRequest error:&error];

데이터를 추가하려면,

NSManagedObject *entityNameObj = [NSEntityDescription insertNewObjectForEntityForName:@"EntityName" inManagedObjectContext:context];
[entityNameObj setValue:@"someValue" forKey:@"someKey"];

컨텍스트를 저장하려면 다음과 같이하십시오.

[((AppDelegate*)[[UIApplication sharedApplication] delegate]) saveContext];


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow