Skip to content

Instantly share code, notes, and snippets.

@ddrscott
Last active December 14, 2015 07:19
Show Gist options
  • Save ddrscott/5049627 to your computer and use it in GitHub Desktop.
Save ddrscott/5049627 to your computer and use it in GitHub Desktop.
Using Parse.com API, how to save and retrieve an object in offline mode?
- testOffline {
// Important! do all methods without Network
PFObject *todo1 = [PFObject objectWithClassName:@"Todo"];
[todo1 setObject:@"Learn Parse API" forKey:@"text"];
[todo1 saveEventually];
PFObject *todo2 = [PFObject objectWithClassName:@"Todo"];
[todo2 setObject:@"Implement iOS" forKey:@"text"];
[todo2 saveEventually];
PFObject *todo3 = [PFObject objectWithClassName:@"Todo"];
[todo3 setObject:@"Implement Android" forKey:@"text"];
[todo3 saveEventually];
}
- testOfflineSometimeLaterButStillOffline {
// still offline
PFQuery *query = [PFQuery queryWithClassName:@"Todo"];
query.cachePolicy = kPFCachePolicyCacheElseNetwork;
NSArray * results = [query findObjects];
NSLog(@"Why are results empty? results => %@", results);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment