core data in modern times

28
Core Data in Modern Times Jorge D. Ortiz-Fuentes @jdortiz #CoreDataMT

Upload: jorge-ortiz

Post on 25-Jul-2015

205 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Core Data in Modern Times

Core Data in Modern Times

Jorge D. Ortiz-Fuentes @jdortiz

#CoreDataMT

Page 2: Core Data in Modern Times

A Canonical Examples production

#CoreDataMT

Page 3: Core Data in Modern Times
Page 4: Core Data in Modern Times

Agenda★Background info

★Comparisons

• Realm

• Android Content Providers

★Concurrency in Core Data

★Threats to Core Data

★Protect yourself

Page 5: Core Data in Modern Times

Background Info

Page 6: Core Data in Modern Times

Core Data concepts★Data persistence

• Objects <-> Data

★ Relationships

• 1-1

• 1-M

• M-M

★ Store independence

Page 7: Core Data in Modern Times

Core Data

Persistent Store

Persistent Store

Persistent Store Coordinator Managed Object

Model

Managed Object Context

MO MO MO MO MO

Page 8: Core Data in Modern Times

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

Page 9: Core Data in Modern Times

FetchedResultsController Anatomy

★ iOS only

★Controller

• uses a fetch request

• coordinates getting data and caches them

• notifies of changes

Page 10: Core Data in Modern Times

Bindings

★OS X only

★Sync UI and Coredata

★Reduce the amount of code required

Page 11: Core Data in Modern Times

Comparisons are odious

Page 12: Core Data in Modern Times

Realm

Page 13: Core Data in Modern Times

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

Page 14: Core Data in Modern Times

Android Content Providers

Page 15: Core Data in Modern Times

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

Page 16: Core Data in Modern Times

Concurrency in Core Data

Page 17: Core Data in Modern Times

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

Page 18: Core Data in Modern Times

Good practices

★Avoid premature optimization

★Have a police for when to use concurrency

★Really follow 1 & 2

Page 19: Core Data in Modern Times

Also available now

★Batch updates (Brent Simmons’ problem)

★Asynchronous fetching

Page 20: Core Data in Modern Times

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

Page 21: Core Data in Modern Times

Threats to Core Data

Page 22: Core Data in Modern Times

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?

Page 23: Core Data in Modern Times

Protect yourself

Page 24: Core Data in Modern Times

– Robert C Martin (Uncle Bob)

“The database is a detail!”

Page 25: Core Data in Modern Times

Clean Architecture

View (VC) Presenter

Wireframe

Interactor Repository

Persistence

WSC

Page 26: Core Data in Modern Times

canonicalexamples.com coupon:

COCOAHEADSNL

Page 27: Core Data in Modern Times

Thank you!

Page 28: Core Data in Modern Times

@jdortiz #CoreDataMT