core data in modern times

Post on 25-Jul-2015

205 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Core Data in Modern Times

Jorge D. Ortiz-Fuentes @jdortiz

#CoreDataMT

A Canonical Examples production

#CoreDataMT

Agenda★Background info

★Comparisons

• Realm

• Android Content Providers

★Concurrency in Core Data

★Threats to Core Data

★Protect yourself

Background Info

Core Data concepts★Data persistence

• Objects <-> Data

★ Relationships

• 1-1

• 1-M

• M-M

★ Store independence

Core Data

Persistent Store

Persistent Store

Persistent Store Coordinator Managed Object

Model

Managed Object Context

MO MO MO MO MO

Core Data Virtues★Visual model

★Seamless integration with Objective-C

★Relationships, deletion rules, Faulting & Uniquing

★Undo management and Change tracking

★KVC & KVO

★Filtering, sorting, grouping

★Versioning and migration

★Merge policies

FetchedResultsController Anatomy

★ iOS only

★Controller

• uses a fetch request

• coordinates getting data and caches them

• notifies of changes

Bindings

★OS X only

★Sync UI and Coredata

★Reduce the amount of code required

Comparisons are odious

Realm

Realm: Pros & Cons★Born mobile

★Models in code(PK)

★Built in encryption

★Multi-thread & Multi-process

★Good performance

★No delete rules

★No fine grained notifications (KVO)

★No null properties

★No sync solutions

Android Content Providers

Android Content★Content providers

• Abstract data sources

• Access to data via URI (REST style)

• It can be exported to other apps

• Thread safety via synchronized (or multi-instance)

★Content resolver to map authorities to providers

Concurrency in Core Data

Background Queue

Main Queue

Single process approach

★ Context

• Private

• MainQueue

★Nested contexts

• Save pushes changes to parent (no I/O)

• Parent saves in the background

child MOC

pStore

parent MOC

Good practices

★Avoid premature optimization

★Have a police for when to use concurrency

★Really follow 1 & 2

Also available now

★Batch updates (Brent Simmons’ problem)

★Asynchronous fetching

UIManagedDocument

★Uses the model in the bundle

★Async I/O

★Completion blocks after opening or saving

★Parent is in background and autosaves

★Also additional data

Threats to Core Data

Threats★Swift

• Introspection is still half baked (@NSManaged)

• Many features of Cocoa depend on the runtime

★ Lack of multi-process capabilities

★Apple generated doubts:

• Photos using

• Removed from Lister?

Protect yourself

– Robert C Martin (Uncle Bob)

“The database is a detail!”

Clean Architecture

View (VC) Presenter

Wireframe

Interactor Repository

Persistence

WSC

canonicalexamples.com coupon:

COCOAHEADSNL

Thank you!

@jdortiz #CoreDataMT

top related