Reading files with NSString error


I have a question about the example to read files on p.153. I get an error on the first line of this statement.

NSString *str = [[NSString alloc] initWithContentsOfFile:@"/etc/resolve.conf"
Error:&error ] ;
The error states "Receiver type ‘NSString’ for instance message does not declare a method with selector
’initWithContentsOfFile:encoding error.’

I have checked and checked for spelling mistakes, and I can’t find any. Please help me understand what is happening.
Learning about files is very important to me.

Thanks in advance,
– Bob Ayres


C and Objective-C are case sensitive; your last argument should be named “error”, not “Error.”


Thanks very much for catching my mistake. I am indeed humbled.


You’re welcome. I was keeping my fingers crossed that was the right answer.