small medium large xlarge

Generic-user-small
30 Sep 2010, 04:13
Richard Tamesis (4 posts)

In chapter 10 p. 221, when I use for( NSString *eachMonth in monthsArray ), I get a warning that says: ‘NSString’ may not respond to ‘-countByEnumeratingWithState:objects:count:’

The program still builds and runs correctly without any problem despite the warning. Why is this happening?

Generic-user-small
30 Sep 2010, 09:55
Tim Isted (105 posts)

Hi Richard, please can you post the rest of the code for the @displaySomeText:@ method?

It sounds like the pointer type you’ve used for @monthsArray@ is an @NSString@ rather than an @NSArray@, even though the object you create for it to point to is correctly an @NSArray@.

Does the first line of code in the method look like this, by any chance? ` NSString *monthsArray = [NSArray arrayWithObjects: … etc … `

If so, the compiler thinks you’re trying to enumerate over an @NSString@ object, hence the warning. At runtime, though, the object pointed to by @monthsArray@ will be an @NSArray@, so all will be fine. The initial @NSString@ in the line above should be @NSArray@; changing it will satisfy the compiler that all is well.

Otherwise, please post the rest of the method as something else must be going on to cause the compiler to think that @monthsArray@ is an @NSString@.

Generic-user-small
01 Oct 2010, 08:07
Richard Tamesis (4 posts)

Okay, my mistake. I had typed NSString *monthsArray instead of NSArray *monthsArray in the first line of code. That fixed the problem. Thanks.

You must be logged in to comment