Skip to content

Instantly share code, notes, and snippets.

@nebiros nebiros/gist:8963499
Created Feb 12, 2014

Embed
What would you like to do?
// 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
You can’t perform that action at this time.