Questions tagged [core-data]

Core Data is Apple's object modeling and persistence framework for iOS, iPadOS, tvOS, watchOS, and macOS. Xcode provides an object model editor for specifying entities, attributes, and relationships.

Core Data is Apple's object modeling and persistence framework for macOS (), iPadOS (), tvOS (), watchOS () and iOS ().

Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence.

While offering some functionality that one might traditionally associate with a relational database, Core Data, itself, is not a relational database management system. It is an object-oriented framework for managing, storing and retrieving model objects of a MVC (model-view-controller) design. However, in recent years Core Data got some SQL'ish features like having aggregates or subqueries on fetch request. But the core concept is still object-orientated, i. e. relationships are resolved by simply accessing properties instead of queries containing a primary key as a condition.

Core Data provides the developer with a wide array of features to simplify the management of these model objects. Instead of using file management and the arbitrary requests for the given store type, you interact with Objective-C and Swift objects.

The typical file Core Data stores its data into is a SQLite file. Although Core Data supports SQLite as one of its persistent store types, Core Data cannot manage any arbitrary SQLite database. In order to use a SQLite database, Core Data must create and manage the database itself. There is also a binary store type and a memory store type.

Core Data is part of the following SDKs:

  • iOS 3.0 and later,
  • macOS 10.4 and later,
  • Mac Catalyst 13.0 and later,
  • tvOS 9.0 and later,
  • watchOS 2.0 and later.

References

27960 questions
405
votes
26 answers

Core Data: Quickest way to delete all instances of an entity

I'm using Core Data to locally persist results from a Web Services call. The web service returns the full object model for, let's say, "Cars" - could be about 2000 of them (and I can't make the Web Service return anything less than 1 or ALL…
Adaromas
  • 4,063
  • 3
  • 14
  • 5
364
votes
25 answers

Exception thrown in NSOrderedSet generated accessors

On my Lion app, I have this data model: The relationship subitems inside Item is ordered. Xcode 4.1 (build 4B110) has created for me the file Item.h, Item.m, SubItem.h and SubItem.h. Here is the content (autogenerated) of Item.h: #import…
Dev
  • 7,041
  • 6
  • 33
  • 63
315
votes
4 answers

Core Data vs SQLite 3

I am already quite familiar with relational databases and have used SQLite (and other databases) in the past. However, Core Data has a certain allure, so I am considering spending some time to learn it for use in my next application. Is there much…
Jason Medeiros
  • 5,178
  • 3
  • 23
  • 18
296
votes
8 answers

How to Sync iPhone Core Data with web server, and then push to other devices?

I have been working on a method to sync core data stored in an iPhone application between multiple devices, such as an iPad or a Mac. There are not many (if any at all) sync frameworks for use with Core Data on iOS. However, I have been thinking…
Jason
  • 14,035
  • 24
  • 87
  • 151
241
votes
33 answers

Delete/Reset all entries in Core Data?

Do you know of any way to delete all of the entries stored in Core Data? My schema should stay the same; I just want to reset it to blank. Edit I'm looking to do this programmatically so that a user can essentially hit a reset button.
Michael Grinich
  • 4,652
  • 8
  • 27
  • 30
183
votes
26 answers

The model used to open the store is incompatible with the one used to create the store

I created a Core Data model in xcode 3.2 and after upgrading in Xcode 4.2, I then added a new entity of the NSManagedObject subclass (refer to the new entity). First thing, it looks weird because it's not in the same group as the old one. Here is…
dejoong
  • 2,183
  • 5
  • 23
  • 24
183
votes
8 answers

Xcode 4, Core Data Model Version - Set Current Version

I'm confused about how to perform the following function in Xcode 4 to set the model to use after creating a versioned model. Design > Data Model > Set Current Version
Nate Potter
  • 3,170
  • 2
  • 19
  • 24
177
votes
2 answers

Best practice? - Array/Dictionary as a Core Data Entity Attribute

I am new to Core Data. I have noticed that collection types are not available as attribute types and would like to know what the most efficient way is of storing array/dictionary type data as an attribute (e.g. the elements that make up an address…
RunLoop
  • 19,113
  • 21
  • 89
  • 146
177
votes
9 answers

Cocoa Core Data efficient way to count entities

I read much about Core Data.. but what is an efficient way to make a count over an Entity-Type (like SQL can do with SELECT count(1) ...). Now I just solved this task with selecting all with NSFetchedResultsController and getting the count of the…
erazorx
  • 1,977
  • 2
  • 15
  • 12
170
votes
7 answers

iphone Core Data Unresolved error while saving

I am getting a strange error message from the core data when trying to save but the problem that the error is not reproducible ( it appears at different times when doing different tasks) the error message: Unresolved error Domain=NSCocoaErrorDomain…
Ahmed Kotb
  • 6,019
  • 5
  • 31
  • 52
168
votes
4 answers

How to delete an old/unused Data Model Version in Xcode

How can I delete an old Data Model in Xcode? The option is disabled on the menu. (The models I want to delete have not been released to the public - they are interim development models.)
SAHM
  • 3,747
  • 4
  • 37
  • 77
158
votes
8 answers

Does every Core Data Relationship have to have an Inverse?

Let's say I have two Entity classes: SocialApp and SocialAppType In SocialApp I have one Attribute: appURL and one Relationship: type. In SocialAppType I have three Attributes: baseURL, name and favicon. The destination of the SocialApp relationship…
Alex Reynolds
  • 91,635
  • 50
  • 223
  • 320
147
votes
11 answers

How to filter NSFetchedResultsController (CoreData) with UISearchDisplayController/UISearchBar

I'm trying to implement search code in my CoreData-based iPhone app. I'm not sure how to proceed. The app already has an NSFetchedResultsController with a predicate to retrieve the data for the primary TableView. I want to make sure I'm on the…
jschmidt
  • 2,848
  • 3
  • 20
  • 26
138
votes
13 answers

Unable to find specific subclass of NSManagedObject

I'm working on developing an app with Core Data. When I created an instance using: let entity = NSEntityDescription.entityForName("User", inManagedObjectContext: appDelegate.managedObjectContext) let user = User(entity: entity,…
MsrButterfly
  • 1,599
  • 2
  • 10
  • 17
138
votes
13 answers

Adding Core Data to existing iPhone project

I'd like to add core data to an existing iPhone project, but I still get a lot of compile errors: - NSManagedObjectContext undeclared - Expected specifier-qualifier-list before 'NSManagedObjectModel' - ... I already added the Core Data…
swalkner
  • 15,150
  • 25
  • 107
  • 195
1
2 3
99 100