From 8cfbea867b5470a500952117794436a641f435cc Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Mon, 14 Jul 2014 18:55:58 -0700 Subject: [PATCH] docs for background --- docs/src/docs.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/src/docs.md b/docs/src/docs.md index 8bc9f124b8..546ffdbe7b 100644 --- a/docs/src/docs.md +++ b/docs/src/docs.md @@ -433,7 +433,28 @@ Realm can be very efficient when writing large amounts of data by batching toget
{% highlight swift %} +dispatch_async(queue, { + // Get realm and table instances for this thread + var realm = RLMRealm.defaultRealm() + + // Break up the writing blocks into smaller portions + // by starting a new transaction + for (var idx1 = 0; idx1 < 1000; idx1++) { + realm.beginWriteTransaction() + + // Add row via dictionary. Order is ignored. + for (var idx2 = 0; idx2 < 1000; idx2++) { + Person.createInDefaultRealmWithObject( + ["name": "\(idx1)", "age": idx2] + ); + } + + // Commit the write transaction + // to make this data available to other threads + realm.commitWriteTransaction() + } +}); {% endhighlight%} {% highlight objective-c %} @@ -602,7 +623,7 @@ Since the result set is given to us as an array we can simply add it straight to {% highlight swift %} //Extract the array of venues from the response -var venues = json.objectForKey("venues") as Array +var venues: AnyObject! = json.objectForKey("venues") defaultRealm.beginWriteTransaction() // Save one Venue object (& dependents) for each element of the array