What is __NSCFArray in AFNetworking 2.0 response?

2019-03-07 09:16发布

What is __NSCFArray in this AFNetworking 2.0 response:

- (void)loadData:(NSMutableArray *) resDic
{
    ... 
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {            
        NSLog(@"%@",[responseObject class]);  //__NSCFArray   
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Failure: %@", error);
    }];
    [operation start];
}

How can I convert it to NSArray?

2条回答
迷人小祖宗
2楼-- · 2019-03-07 09:37

It is already an NSArray, something you can verify by calling:

BOOL isKindOfArray = [responseObject isKindOfClass:[NSArray class]];

NSArray is implemented as a class cluster and one of the private subclasses that it might return is __NSCFArray.

The point of a class cluster is that the framework can provide different implementations under the hood that you don't really have to care about. As far as you should be concerned, it's an NSArray.

查看更多
虎瘦雄心在
3楼-- · 2019-03-07 09:53

NSArray is a class cluster. This basically means that NSArray objects could be made up of one of several different actual implementations and __NSCFArray is one of the classes (probably the most common) that NSArray can use to implement an array.

Just use the __NSCFArray as you would any other NSArray and it'll work fine.

查看更多
登录 后发表回答