0Pricing
Objective-C iOS Development for Legacy & Enterprise Apps · 강의

Core Data 기초

객체 그래프와 영구 저장소를 관리하는 Apple 프레임워크인 Core Data의 기본 사항을 이해합니다.

Core Data 기초은(는) CoddyKit의 무료 Objective-C iOS Development for Legacy & Enterprise Apps 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Objective-C iOS Development for Legacy & Enterprise Apps 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Objective-C iOS Development for Legacy & Enterprise Apps 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Welcome to Core Data

Hello! Today we're diving into Core Data, Apple's powerful framework for managing and persisting an application's object graph.

It helps you store your app's data on disk and retrieve it efficiently.

Core Data is Not a Database

It's crucial to understand: Core Data itself is not a database. Instead, it's an object graph management framework.

  • It helps you manage your data objects in memory.
  • It provides tools to save these objects to a persistent store (which *can* be a database like SQLite).
  • Think of it as an abstraction layer over the actual storage.

The Core Data Stack

Core Data relies on a 'stack' of objects that work together. Understanding these components is key:

  • Managed Object Model: Your app's data schema.
  • Persistent Store Coordinator: Connects the model to the store.
  • Persistent Store: The actual storage (e.g., SQLite file).
  • Managed Object Context: Your scratchpad for data interaction.

Managed Object Model (NSManagedObjectModel)

The Managed Object Model (NSManagedObjectModel) defines your application's data structure.

  • It's where you specify entities (like tables in a database).
  • Each entity has attributes (properties, e.g., name, age).
  • You can also define relationships between entities.

You typically create this visually in Xcode using the data model editor (a .xcdatamodeld file).

Persistent Store Coordinator (NSPersistentStoreCoordinator)

The Persistent Store Coordinator (NSPersistentStoreCoordinator) acts as a bridge.

  • It takes your NSManagedObjectModel.
  • It connects it to one or more persistent stores.
  • Common store types include SQLite, XML, or binary files. SQLite is the most common for iOS apps.

Persistent Store (NSPersistentStore)

The Persistent Store (NSPersistentStore) is where your data actually lives on disk.

When you choose an SQLite store, Core Data creates and manages an SQLite database file. You don't interact with SQL directly; Core Data handles it for you.

Managed Object Context (NSManagedObjectContext)

The Managed Object Context (NSManagedObjectContext) is your primary interface for interacting with Core Data.

  • Think of it as a 'scratchpad' where you create, retrieve, update, and delete objects.
  • Changes made here are temporary until you 'save' the context.
  • It tracks all changes and reports them to the Persistent Store Coordinator when saved.

Working with NSManagedObject

Data records in Core Data are represented by instances of NSManagedObject (or its subclasses).

They are similar to regular Objective-C objects, but their properties are managed by Core Data.

Here's how you'd typically create and set properties on such an object (assuming a context is ready):

#import <Foundation/Foundation.h>

// In a real Core Data app, 'Person' would be
// an NSManagedObject subclass generated from
// your data model.

@interface Person : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, assign) NSInteger age;
@end

@implementation Person
@end

int main(int argc, const char * argv[]) {
  @autoreleasepool {
    // Normally, this object would be created
    // via NSManagedObjectContext's insertNewObjectForEntityForName method.
    // For this simple runnable example, we use a plain NSObject.
    Person *newPerson = [[Person alloc] init];
    newPerson.name = @"Alice";
    newPerson.age = 30;

    NSLog(@"Created person: %@, age: %ld", newPerson.name, (long)newPerson.age);
    // In a real Core Data app, you'd then save the context
    // to persist this NSManagedObject instance.
  }
  return 0;
}

Saving Your Changes

After you create, modify, or delete NSManagedObject instances within a NSManagedObjectContext, these changes are only in memory.

To persist them to the Persistent Store, you must tell the context to save:

NSError *error = nil;
[context save:&error];
if (error) {
NSLog(@"Error saving context: %@", error);
}

It's crucial to always check for errors when saving!

Quick Check: Core Data Roles

Which Core Data component is responsible for defining your application's data structure, including entities and their attributes?

Core Data Fundamentals Recap

We've covered the basics of Core Data, Apple's object graph management framework. Remember:

  • It's not a database, but uses them for storage.
  • The Core Data Stack includes Model, Coordinator, Store, and Context.
  • Managed Object Model defines your data.
  • Persistent Store Coordinator connects model to store.
  • Persistent Store is the physical data location.
  • Managed Object Context is your interaction point.
  • You interact with NSManagedObject instances and must save the context to persist changes.

Next, we'll explore fetching data and more complex interactions!

자주 묻는 질문

“Core Data 기초” 강의는 무료인가요?

네 — “Core Data 기초” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Objective-C iOS Development for Legacy & Enterprise Apps 강의 전체를 잠금 해제할 수 있습니다. Objective-C iOS Development for Legacy & Enterprise Apps 강의에는 총 4개의 강의가 포함되어 있습니다.

“Core Data 기초”에서 뭘 배우나요?

객체 그래프와 영구 저장소를 관리하는 Apple 프레임워크인 Core Data의 기본 사항을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Objective-C iOS Development for Legacy & Enterprise Apps을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Objective-C iOS Development for Legacy & Enterprise Apps을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Objective-C iOS Development for Legacy & Enterprise Apps은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“Core Data 기초” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Objective-C iOS Development for Legacy & Enterprise Apps 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Objective-C iOS Development for Legacy & Enterprise Apps 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 속성 목록과 보관
  2. Core Data 기초
  3. FMDB를 활용한 SQLite 통합
  4. NSUserDefaults로 환경 설정 저장하기
← Objective-C iOS Development for Legacy & Enterprise Apps(으)로 돌아가기