|
1 | 1 | # Local Datastore
|
2 | 2 |
|
3 |
| -The Parse iOS/OS X SDK provides a local datastore which can be used to store and retrieve `PFObject`s, even when the network is unavailable. To enable this functionality, add `libsqlite3.dylib` and add `isLocalDatastoreEnabled = true` to the `ParseClientConfiguration` block used in `Parse.initialize()`. |
| 3 | +The Parse iOS/OS X SDK provides a local datastore which can be used to store and retrieve `PFObject`s, even when the network is unavailable. To enable this functionality add `isLocalDatastoreEnabled = true` to the `ParseClientConfiguration` block used in `Parse.initialize()` or call `Parse.enableLocalDatastore()` prior to initializing Parse. |
4 | 4 |
|
5 | 5 | <div class="language-toggle" markdown="1">
|
6 | 6 | ```objective_c
|
7 | 7 | @implementation AppDelegate
|
8 | 8 |
|
9 | 9 | - (void)application:(UIApplication *)application didFinishLaunchWithOptions:(NSDictionary *)options {
|
10 |
| - [Parse enableLocalDatastore]; |
11 |
| - [Parse setApplicationId:@"parseAppId" clientKey:@"parseClientKey"]; |
| 10 | + ParseClientConfiguration *configuration = [ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) { |
| 11 | + configuration.applicationId = @"parseAppId"; |
| 12 | + configuration.clientKey = @"parseClientKey"; |
| 13 | + configuration.server = @"parseServerUrlString"; |
| 14 | + configuration.localDatastoreEnabled = YES; |
| 15 | + }]; |
| 16 | + [Parse initializeWithConfiguration:configuration]; |
12 | 17 | }
|
13 | 18 |
|
14 | 19 | @end
|
@@ -74,28 +79,28 @@ Storing objects is great, but it's only useful if you can then get the objects b
|
74 | 79 | ```objective_c
|
75 | 80 | PFQuery *query = [PFQuery queryWithClassName:@"GameScore"];
|
76 | 81 | [query fromLocalDatastore];
|
77 |
| -[[query getObjectInBackgroundWithId:@"xWMyZ4YE"] continueWithBlock:^id(BFTask *task) { |
78 |
| - if (task.error) { |
79 |
| - // Something went wrong. |
80 |
| - return task; |
81 |
| - } |
| 82 | +[query getObjectInBackgroundWithId:"" block:^(PFObject * _Nullable object, NSError * _Nullable error) { |
| 83 | + if (!error) { |
| 84 | + // Success |
| 85 | + } else { |
| 86 | + // Fail! |
| 87 | + } |
| 88 | +} |
82 | 89 |
|
83 | 90 | // task.result will be your game score
|
84 | 91 | return task;
|
85 | 92 | }];
|
86 | 93 | ```
|
| 94 | + |
87 | 95 | ```swift
|
88 | 96 | let query = PFQuery(className: "GameScore")
|
89 | 97 | query.fromLocalDatastore()
|
90 |
| -query.getObjectInBackgroundWithId("xWMyZ4YE").continueWithBlock { |
91 |
| - (task: BFTask!) -> AnyObject in |
92 |
| - if let error = task.error { |
93 |
| - // Something went wrong. |
94 |
| - return task; |
| 98 | +query.getObjectInBackground(withId: "string") { (object, error) in |
| 99 | + if error == nil { |
| 100 | + // Success! |
| 101 | + } else { |
| 102 | + // Failure! |
95 | 103 | }
|
96 |
| - |
97 |
| - // task.result will be your game score |
98 |
| - return task; |
99 | 104 | }
|
100 | 105 | ```
|
101 | 106 | </div>
|
|
0 commit comments