MikeJ MikeJ - 3 years ago 180
Objective-C Question

Xcode 7 - Incompatible block pointer types

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

Answer Source

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);
}];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download