In the tutorial there is the following declaration:
-(BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile;
I’m interpreting this as writeToFile method returns a BOOL result. It takes 2 parameters. The first is an NSString reference. The second is the result of calling atomically and passing it a BOOL value.
Did I get that right?
The tutorial goes on to say you call the above method like this:
BOOL result = [myData writeToFile:@"/tmp/log.txt" atomically:NO];
which is find. But I wonder if I MUST use “atomically:NO”
Could I have done something like
resultOfAtomically = atomically:NO
BOOL result = [ myData writeToFile:@"/tmp/log.txt" resultOfAtomically ];
assuming I declared resultOfAtomically properly.
Also, does prepending @ to "/tmp/log.txt" mean something like “give me the reference NOT the value” ?
The text
atomicallyintroduces the second parameter of thewriteToFile:atomically:method, it is not a separate function. Therefore, you cannot call simplyatomically:NO. This would be correct, however:BOOL myBool = NO;BOOL result = [myData writeToFile:@"/tmp/log.txt" atomically:myBool];When talking about Objective-C methods, you would not call this method “writeToFile”, you would call it “writeToFile:atomically:”. By this syntax you know that the method expects two parameters (one for each colon).
Here’s a way to think about how the method declaration breaks down:
-(BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile;-= defining an instance method (+would be for a class method).(BOOL)= returning a boolean value.write= this method is about writing something (nothing magic, just a friendly word choice – could have beenprintor something else).ToFile:(NSString *)path= the first parameter of the method, path, is an NSString pointer and the friendly text “ToFile” (again just a word choice, nothing special) hints that I need to provide a file path for that parameter.atomically:(BOOL)useAuxiliaryFile;= the second parameter of the method, useAuxiliaryFile, is a boolean and the friendly text “atomically” (still nothing special) hints that the boolean value determines whether or not to write the file atomically.