Reading files with NSString error


#1

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"
encoding:NSASCIIStringEncoding
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


#2

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


#3

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


#4

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