Xcode 7 - 不兼容的块指针类型

6

这段代码在Xcode 6中运行良好,但现在在Xcode 7中无法编译。有什么办法可以修复并解释为什么这是Xcode 7的问题?

不兼容的块指针类型发送'void (^)(SKSpriteNode *__strong,NSUInteger,BOOL *)'到参数类型'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个回答

7

iOS9 / Xcode7似乎改变了一些接口。在这种情况下,您可以通过键入[self.children enum,然后按下Ctrl+Space并从列表中选择适当的方法来最轻松地修复它。这将为您提供一个具有新块指针类型的代码片段,并且您可以将代码移动到其中。

结果将是这样的:(自动完成后,node变成了obj,我只是重命名了它)

[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);
}];

谢谢,现在已经编译成功了! - MikeJ

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接