Skip to content

Instantly share code, notes, and snippets.

@nebiros
Created February 12, 2014 20:07
Show Gist options
  • Select an option

  • Save nebiros/8963499 to your computer and use it in GitHub Desktop.

Select an option

Save nebiros/8963499 to your computer and use it in GitHub Desktop.
// An implementation.
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// if (!self.isThingsSaved) {
// [self saveThings];
// }
[self saveThings];
}
- (void)saveThings
{
__weak typeof(self) weakSelf = self;
[thing saveRow:@{kTHTParseKeyPersonRecordId: @(self.person.recordID),
kTHTParseKeyOriginalImage: originalImage ?: [NSNull null],
kTHTParseKeyOriginalThumbnail: originalThumbnail ?: [NSNull null],
kTHTParseKeyThings: self.things}
usingBlock:^(BOOL succeeded, PFObject *aThing, NSError *error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
// TODO: handle errors properly (jfas).
if (error) {
NSLog(@"[ERROR] - %s: %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:@"\n%@\n%@", [error localizedDescription], error.userInfo]);
return;
}
if (succeeded) {
// strongSelf.thingsSaved = YES;
if (strongSelf.delegate && [strongSelf.delegate respondsToSelector:@selector(thingAddedSuccessfully:)]) {
[strongSelf.delegate thingAddedSuccessfully:(THTThing *) aThing];
}
}
}];
}
// strongSelf is nil after viewWillDisappear is executed and the block is call, why?.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment