Problem with textbook code - pg.161



I’ve double and triple checked that I have put the code in properly, but XCode is still giving me an error on this line of code from the example in Chapter 24 on page 161:

The error is: “Size of array has non-integer type ‘id’”.

Now I understand what the error is, but going through all the files, I can’t seem to find why it’s even looking for a size of array?!

Can anyone help me out with this as I want to progress with the book and can’t without getting this code to work!

Thanks, Mark.


There are two problems with the above line:

  1. There are too many square brackets: [[ …]]
    [Remove the outer ones.]

  2. You are missing the assignment operator after the variable url.
    [Add one]

Try this:

By the way, I agree Xcode’s error message is very confusing. I was surprised that it did not say something like “missing ‘=’ after …”

But there is a reason behind this madness. Xcode’s Objective-C compiler’s parser is using a context-free grammar to analyse the static code. So when it sees something like T foo […] or T *bar […] in your code, the parser thinks that you are declaring an array with size “…” In this case, “…” is the URL string which is a constant string object with a very large address that looks like a negative number to the compiler.


Thanks so much for your response - such a simple thing, maybe it was time for a break.

Thanks also for your explanation of the error message, it makes sense. p.s. XCode was also shouting for the additional [] hence why I put those in - something to do with arrays I guess!