What is the best practice when nesting method calls or using one-shot variables?
Should you never use one-shot variables?
example:
[persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
configuration:nil
URL:[NSURL fileURLWithPath: [applicationSupportDirectory stringByAppendingPathComponent: @"storedata"]]
options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption]
error:&error];
Should you always break up a nested method into one-shot variables?
example:
NSNumber *yesNumber = [NSNumber numberWithBool:YES];
NSDictionary *optionsDict = [NSDictionary dictionaryWithObject:yesNumber
forKey:NSMigratePersistentStoresAutomaticallyOption];
NSString *urlPath = [applicationSupportDirectory stringByAppendingPathComponent:@"storedata"];
NSURL *url = [NSURL fileURLWithPath: urlPath];
[persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
configuration:nil
URL:url
options:optionsDict
error:&error];
Or should you use some combination of the two?
example:
NSDictionary *optionsDict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
forKey:NSMigratePersistentStoresAutomaticallyOption];
NSURL *url = [NSURL fileURLWithPath: [applicationSupportDirectory stringByAppendingPathComponent:@"storedata"]];
[persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
configuration:nil
URL:url
options:optionsDict
error:&error];
I tend to go with a combination of the two but I would like to hear what everyone else has to say about this. In case it is not clear above, these "one-shot variables" are created for the sole purpose of breaking up the nested method and will not be used anywhere.