Using NSLog(NSString * format)
When using Cocoa objects (those subclassed from
NSObject), be sure to always place @ (“at” symbol) before the output string to ensure the description for the object is sent. Otherwise, warning: passing argument 1 of 'NSLog' from incompatible pointer type is returned. Also, using
%@ for the format of any NSObject will return whatever is returned from the description method. This is great for “cowboy” coding.
// get the first string of an index
NSString *firstChar = [[NSString alloc] initWithString:[currentProductString substringToIndex:0]];
// report it
NSLog(@"firstChar = %@", firstChar); // note the @ before the output string and the %@ format.
The
description method can be overridden in any custom classes subclassed from NSObject.
[NSString writeToFile:...]
Selecting an encoding is required here.
// setOutput is an NSString; write to file is a class method.
NSError *writeError;
[setOutput writeToFile:[destinationFolder stringByAppendingPathComponent:[NSString stringWithFormat:@“my”TextFile.txt”]] atomically:YES encoding:kProjectEncoding error:&writeError];