1

I have the following in a success block for an AFNetworking getPath call:

+(void)allItemsWithBlock: (void (^)(NSArray *items)) block
{
   ...
   NSMutableArray *mutableItems = [NSMutableArray array];
   for (NSDictionary *attributes in [responseObject valueForKey:@"data"]) {
      Item *item = [[Item alloc] initWithAttributes:attributes];
      [mutableItems addObject:item];
   } 
   NSLog(@"here is a count: %i", [mutableItems count]);
   if(block){
      block(mutableItems);
   }

and in the block that gets passed in, I have the following but get the error listed as a comment:

[Item allItemsWithBlock:^(NSArray *items){
    for(Item *thisItem in *items){  // The type 'NSArray' is not a pointer to a fast-enumerable object
      NSLog(@"in the block here");
    }
}];

I've read up on trying to fast-enumeration but am not sure what the problem is. Is the NSMutableArray -> NSArray an issue? Is it because this array is created in a block and thus could be seen as possibly still 'open for change'? I have seen code like this before in our projects and doesn't seem to be a problem.

thx for any help

3
  • 1
    Don't prefix methods w/get, please. That is reserved for a very special purpose. Commented Aug 12, 2013 at 0:49
  • To be more specific, get is typically used when the caller must provide their own buffer. For example, NSString has a method getCharacters:range: where the caller must provide a buffer. Similarly, NSArray has a method called getObjects:range:. Another example, NSStream has a class method getStreamsToHost:port:inputStream:outputStream: where the method returns two streams via "output" parameters. Commented Aug 12, 2013 at 1:04
  • thx @bburn just testing out a few things, updated Commented Aug 12, 2013 at 1:21

1 Answer 1

6

This is because NSArray *items is already a pointer to an array, *items is trying to find a pointer to a pointer, which it is not.

Just replace:

for(Item *thisItem in *items){

with:

for(Item *thisItem in items){
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.