Skip to content

Instantly share code, notes, and snippets.

@funkyboy
Created April 1, 2014 14:01
Show Gist options
  • Select an option

  • Save funkyboy/9914571 to your computer and use it in GitHub Desktop.

Select an option

Save funkyboy/9914571 to your computer and use it in GitHub Desktop.
- (void)createNewPost:(id)sender {
if (!_posts) {
_posts = [[NSMutableArray alloc] init];
}
SMPost *p = [[SMPost alloc] init];
p.postTitle = [NSString stringWithFormat:@"No title %i", _posts.count ];
p.postBody = @"No body";
[p saveObjectWithCompletion:^(SMPost *post, NSError *error) {
if (error == nil) {
NSLog(@"created post on server %@", post);
[_posts insertObject:post atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0
inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
} else {
NSLog(@"error in saving %@", error);
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment