🗄️

Core Data

iOS 3+

A powerful object graph and persistence framework that has been the standard for iOS data management since iOS 3. Core Data provides object lifecycle management, undo/redo, and efficient data storage.

Data Persistence
Official Apple Documentation →
iOS Version Compatibility
99.8%
coverage

of iOS users worldwide can use Core Data (iOS 3+ required)

iOS VersionMarket ShareStatus
iOS 18.730.3%Supported
iOS 18.629.8%Supported
iOS 26.110.7%Supported
iOS 18.56.0%Supported
iOS 16.72.3%Supported
iOS 26.22.0%Supported
iOS 18.31.8%Supported
iOS 15.81.8%Supported
iOS 11.01.7%Supported
iOS 17.61.7%Supported

Key Features

Object graph management with relationships

Automatic undo and redo support

Efficient data storage with SQLite backend

Data validation and migration tools

Fault handling for memory efficiency

Mature and battle-tested framework

Code Examples

Define an Entity

Create a Core Data entity using NSManagedObject

import CoreData

@objc(Person)
public class Person: NSManagedObject {
    @NSManaged public var name: String
    @NSManaged public var age: Int16
    @NSManaged public var email: String?
}

extension Person {
    @nonobjc public class func fetchRequest() -> NSFetchRequest<Person> {
        return NSFetchRequest<Person>(entityName: "Person")
    }
}

Save Data

Create and save a new managed object

import CoreData

func createPerson(context: NSManagedObjectContext) {
    let person = Person(context: context)
    person.name = "John Doe"
    person.age = 30
    person.email = "john@example.com"
    
    do {
        try context.save()
        print("Person saved successfully")
    } catch {
        print("Error saving: \(error)")
    }
}

Fetch Data

Query data with NSFetchRequest

import CoreData

func fetchPeople(context: NSManagedObjectContext) -> [Person] {
    let fetchRequest: NSFetchRequest<Person> = Person.fetchRequest()
    fetchRequest.predicate = NSPredicate(format: "age > %d", 25)
    fetchRequest.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true)]
    
    do {
        let people = try context.fetch(fetchRequest)
        return people
    } catch {
        print("Error fetching: \(error)")
        return []
    }
}

Frequently Asked Questions

What is Core Data?

A powerful object graph and persistence framework that has been the standard for iOS data management since iOS 3. Core Data provides object lifecycle management, undo/redo, and efficient data storage.

Which iOS versions support Core Data?

Core Data is available on iOS 3 and later. Currently, 99.8% of iOS users worldwide can use this framework.

What are alternatives to Core Data?

Related frameworks include Swiftdata, Cloudkit. Each has different capabilities and iOS version requirements.