mardi 29 avril 2014

What is the logic behind copying properties into a "fresh" variable for use in a method?


Vote count:

0




The following code is from Apple's Core Data template, but I've seen similar code from many different developers:



- (void)saveContext
{
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil) {
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}


Why is there a new object created for the managedObjectContext? Why is self.managedObjectContext not sufficient. Personally, I would have used just that.


What is the logic behind copying a property into a fresh, local variable when you could simply use the property?



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire