Bad receiver type "int" error when using the book's code


#1

I am getting a “bad receiver type “int”” error on this line of code from the challenge section of the book:

[quote]NSString *nameString = [NSString stingWithContentsOfFile:@"/usr/share/dict/propernames"
encoding:[NSUTF8StringEncoding
error:NULL];[/quote]

It specifically is pointing to this:

I keep checking for mistakes, but I can’t seem to get rid of the error. Can anyone give me some help?


#2

That’s because you are not checking carefully; as a consequence, you are being [color=#FF0000]stung[/color].

Compare this:

NSString *nameString = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames"
                                                            encoding:NSUTF8StringEncoding
                                                                      error:NULL];

#3

Thanks. But even with the fix, I am still getting the same error.


#4

If ibex10’s code didn’t fix it, then the error is likely somewhere else, despite the compiler thinking it’s here.

Can you paste a longer code segment surrounding the snippet you’ve provided?


#5

This is the whole thing:


#6

There is a syntax error: the square bracket [ before NSUTF8StringEncoding token. Delete the square bracket and compile again.


#7

I am having the same problem, and cannot locate any syntax error.

NSString *nameString = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames" usedEncoding:NSUTF8StringEncoding error:NULL];

I am still getting an error: "Incompatible integer to pointer conversion sending “int”.

Can anyone help?