Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
}];
like image 549
MikeJ Avatar asked Sep 22 '15 19:09

MikeJ


1 Answers

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);
}];
like image 90
Rainer Schwarze Avatar answered Oct 13 '22 21:10

Rainer Schwarze