Xcode 7 GM - not able to call enumerateObjectsUsingBlock

你离开我真会死。 提交于 2019-12-11 13:32:53

问题


I just downloaded xcode 7 GM and trying to call the method enumerateObjectsUsingBlock of NSArray with iOS 9 but it shows the following error at build time.

Incompatible block pointer types sending 'void (^)(SKSpriteNode *__strong, NSUInteger, BOOL *)' to parameter of type 'void (^ _Nonnull)(SKNode * _Nonnull __strong, NSUInteger, BOOL * _Nonnull)'

This is the Apple documentation about enumerateObjectsUsingBlock method:

- (void)enumerateObjectsUsingBlock:(void (^)(ObjectType obj,
                                             NSUInteger idx,
                                             BOOL *stop))block

and this is my code:

[self.children enumerateObjectsUsingBlock:^(SKSpriteNode * child, NSUInteger idx, BOOL *stop) {
    child.position = CGPointMake(child.position.x-self.scrollingSpeed, child.position.y);
    if (child.position.x <= -child.size.width){
        float delta = child.position.x+child.size.width;
        child.position = CGPointMake(child.size.width*(self.children.count-1)+delta, child.position.y);
    }
}];

where self.children is a NSArray.

I don't understand, what am I doing wrong?


回答1:


Did you read the error message? Did you notice the "nonnull" in two places? In Xcode 7, there are stricter rules. You have an array which is guaranteed to contain SKNode, not SKSpriteNode. There are pointers required to be nonnull pointers. You'll need to change your code to handle this.



来源:https://stackoverflow.com/questions/32540701/xcode-7-gm-not-able-to-call-enumerateobjectsusingblock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!