Nested method calls versus one-time variables

What is the best practice when calling a nesting method or using one-time variables?

Should you never use one-time 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 a nested method into one-time 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 can say about it. In case it is not clear, these "one-time variables" are created for the sole purpose of breaking the nested method and will not be used anywhere.

+3
source share
3 answers

, " ", ( "release" ) , ), . , , .

+1

, . , , AFAIK.

+1

- , .

SO, (OSV), - . .

, , . . , , OSV, , nil myView.subView, , .

: , , . , - , .

+1

Source: https://habr.com/ru/post/1757928/


All Articles