Xcode 7 - Incompatible block pointer types

梦想的初衷 提交于 2019-12-20 01:43:56

问题


This code worked fine in Xcode 6, but now won't compile in Xcode 7. Any ideas how to fix and why this is an issue in Xcode 7?

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

[self.children enumerateObjectsUsingBlock:^(SKSpriteNode * node, NSUInteger idx,BOOL *stop)
{
    float parallaxRatio = [(NSNumber *)node.userData[@"ParallaxRatio"] floatValue];
    CGPoint childVelocity = CGPointMultiplyScalar(self.velocity, parallaxRatio);
    CGPoint offset = CGPointMultiplyScalar(childVelocity, deltaTime);
    node.position = CGPointAdd(node.position, offset);
}];

回答1:


Several interfaces seem to have changed with iOS9 / Xcode7. In that case you most easily fix it, by typing [self.children enum, then press Ctrl+Space and select the appropriate method from the list. This will give you a code fragment with the new block pointer type and you can move the code in there.

The result would be this: (node was obj after autocompletion, I just renamed it)

[self.children enumerateObjectsUsingBlock:^(SKNode * _Nonnull node, NSUInteger idx, BOOL * _Nonnull stop) 
{
    float parallaxRatio = [(NSNumber *)node.userData[@"ParallaxRatio"] floatValue];
    CGPoint childVelocity = CGPointMultiplyScalar(self.velocity, parallaxRatio);
    CGPoint offset = CGPointMultiplyScalar(childVelocity, deltaTime);
    node.position = CGPointAdd(node.position, offset);
}];


来源:https://stackoverflow.com/questions/32724880/xcode-7-incompatible-block-pointer-types

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