From fa393a53b2be39a470a3eea17cb22d4d267ba996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 29 May 2016 15:44:21 +0200 Subject: [PATCH] FetchedRecordsController: document that callbacks are invoked asynchronously --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0b8ebf8ed..282f790e2 100644 --- a/README.md +++ b/README.md @@ -2720,7 +2720,7 @@ controller.trackChanges( See [Implementing Table View Updates](#implementing-table-view-updates) for more detail on table view updates on iOS. -All callbacks are optional. When you only need to grab the latest results, you can omit the `recordsDidChange` argument name: +**All callbacks are optional.** When you only need to grab the latest results, you can omit the `recordsDidChange` argument name: ```swift controller.trackChanges { controller in @@ -2728,7 +2728,7 @@ controller.trackChanges { controller in } ``` -All callbacks have the fetched record controller itself as an argument: use it in order to avoid memory leaks: +Callbacks have the fetched record controller itself as an argument: use it in order to avoid memory leaks: ```swift // BAD: memory leak @@ -2742,6 +2742,18 @@ controller.trackChanges { controller in } ``` +Unless specified [otherwise](#fetchedrecordscontroller-concurrency), callbacks are invoked, asynchronously, on the main thread. This means that changes made from the main thread are *not* immediately notified: + +```swift +// On the main thread +try dbQueue.inDatabase { db in + try Person(...).insert(db) +} +// Here changes have not yet been notified. +``` + +When you need to take immediate action, force the controller to refresh immediately with its `performFetch` method. In this case, changes callbacks are *not* called. + ### Modifying the Fetch Request