Lecture 14

Lecture 14 - Stanford CS193p Developing Applications for...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Stanford CS193p Fall 2011 Developing Applications for iOS Fall 2011 Stanford CS193p
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Stanford CS193p Fall 2011 To day Core Data Thread Safety NSManagedObjectContext is not thread-safe. What to do about that. Core Data and Table View Very common way to view data from a Core Data database So it is made very easy with NSFetchedResultsController Big ol’ demo Photomania Browse recent photos by Photographer who took them
Background image of page 2
Stanford CS193p Fall 2011 Core Data Thread Safety NSManagedObjectContext is not thread safe Luckily, Core Data access is usually very fast, so doing it in the main thread is mostly ±ne. Always safe to access from the thread in which it (or its UIManagedDocument ) was created. Feel free to take this approach for your homework (it’s the most straightforward). Another Approach [context performBlock:^{ // o r performBlockAndWait: // do stuff with context }]; This will make sure that the code in the block happens on the context ’s safe thread. Note that this might well be the main thread, so you’re not necessarily getting “multithreaded.” Advanced Approach Some contexts (including Core Data ones) have a parentContext (a @property on NSMOC ). The parentContext will almost always have its own thread , so you can performBlock: on it. But it is a different context, so you’ll have to save and then refetch to see the changes.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Stanford CS193p Fall 2011 Core Data and Table View NSFetchedResultsController Hooks an NSFetchRequest up to a UITableViewController NSFetchedResultsController can answer all of the UITableViewDataSource protocol’s questions! For example .
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

Lecture 14 - Stanford CS193p Developing Applications for...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online