Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Introduction to Core Data with Swift 2 Deleting and Updating Data Refactoring the Data Source

Alistair Cooper
PLUS
Alistair Cooper
Courses Plus Student 7,020 Points

Core Data in Swift 3 / Updating a Core Data app / Pasan RULES!

Awesome tutorial Pasan! Crushed it!!

I haven't checkout out Swift 3 yet but I gather Core Data has changed a bit. Any idea how much? Do these concepts still apply? If I were to build an app using Core Data in Swift 2.2 would the migrator port it to Swift 3 "easily"? Or would it be better to build in Swift 3 now?

Let's say you released a todo app with that schema but then wanted to update the app later with more attributes to the item entity how would that affect current users (who already have data stored)?

Thank you!
-Alistair

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Alistair Cooper,

The changes to Core Data with iOS 10 are:

The Core Data framework (CoreData.framework) includes the following enhancements:

  • NSPersistentStoreCoordinator now maintains a connection pool for SQLite stores. Root NSManagedObjectContext objects (those without parent MOCs) transparently support concurrent fetching and faulting without serializing against each other.

  • NSManagedObjectContext objects with SQLite stores in WAL journal_mode support a new feature called query generations. These allow a MOC to be pinned to a version of the database at a point in time and perform all future fetching and faulting against that version of the database. Pinned MOCs are moved to the most recent transaction with any save, and query generations do not survive the process's life time.

  • The new NSPersistentContainer class provides your app with a high-level integration point that maintains references to your NSPersistentStoreCoordinator, NSManagedObjectModel, and other configuration resources. Core Data now has tighter integration with Xcode and automatically generates and updates your NSManagedObject subclasses.

  • NSManagedObject includes several additional convenience methods, making it easier to fetch and create subclasses. NSManagedObject subclasses that have a 1:1 relationship with an entity now support entity.

  • Core Data introduces several API adjustments that provide better integration with Swift, including parameterized NSFetchRequest objects.

For more information, see Core Data Framework Reference.

Source: https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html

Swift 3 doesn't necessarily directly affect CoreData, just the syntax used to use the CoreData framework.

Good Luck