Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Created April 24, 2012 23:22
Show Gist options
  • Select an option

  • Save tonyarnold/2484539 to your computer and use it in GitHub Desktop.

Select an option

Save tonyarnold/2484539 to your computer and use it in GitHub Desktop.
A crashy piece of code under ARC
- (void)dwk_postChangeNotification:(NSString *)notificationName newValue:(id)newValue oldValue:(id)oldValue
{
if (CBIsEmpty(newValue) || CBIsEmpty([self fileModificationDate])) {
return;
}
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithCapacity:2];
[userInfo setObject:newValue forKey:kNotificationOldValueKey];
if (CBIsNotEmpty(oldValue)) {
[userInfo setObject:oldValue forKey:kNotificationNewValueKey];
}
NSNotification *changeNotification = [NSNotification notificationWithName:notificationName object:self userInfo:userInfo];
void (^saveCompletionHandler)(BOOL) = [^(BOOL success) {
[[NSNotificationCenter defaultCenter] postNotification:changeNotification];
} copy];
// The document has unsaved changes
if (UIDocumentStateNormal != [self documentState]) {
saveCompletionHandler (YES);
} else {
[[DWKDocumentsController sharedController] saveDocumentToDisk:self completionHandler:saveCompletionHandler];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment