2014-02-25 3 views
0

내 게임에 10 카운트 루프를 추가하려고하는데 코드를 실행하면 "variable not assignable missing__block"오류 메시지가 생성됩니다. 아무도 내가 잘못 가고 올바른 방향으로 나를 가리 키도록 말할 수 있습니까?변수를 할당 할 수 없음 missing__block

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    CGPoint currentLocation = [[touches anyObject] locationInNode:self]; 
    CGPoint previousLocation = [[touches anyObject] previousLocationInNode:self]; 
    CGRect shipRect = _ship.frame; 
    if (CGRectContainsPoint(shipRect, previousLocation)) 
    { 
     [self launch:10 p1:currentLocation p2:previousLocation rect1:shipRect]; 
    } 
} 

-(void)launch:(int)count p1:(CGPoint) currentLocation p2:(CGPoint) previousLocation rect1:(CGRect) shipRect 
{ 
    CGPoint lvPosition = CGPointMake(_ship.position.x - (previousLocation.x - currentLocation.x), _ship.position.y); 
_ship.position = lvPosition; 

    SKAction *sound = [SKAction playSoundFileNamed:@"slideup.mp3" waitForCompletion:NO]; 
    SKAction *moveNode = [SKAction moveByX:lvPosition.x y:10.0 duration:3.0]; 

    [_ship runAction: sound]; 
    [_ship runAction: moveNode completion:^{[self launch:count-- p1:currentLocation p2:previousLocation rect1:shipRect];}]; /*variable not assignable missing__block error*/ 

} 
+0

매개 변수를 변경하는 것은 바람직하지 않습니다. 블록에서 또는하지 말아야합니다. – sage444

+0

루프를 추가하려고하는데 코드 샘플에 루프가 없습니다. 실수로 표본에서 뭔가를 놓친 적이 있습니까? – CRD

답변

1

난 당신이 __block로 정의되지 않은 변수 count을 감소하려고 생각합니다. 당신은 예를 __block int count;를 들어, __block와 블록 내부에 변경하려는 각 변수를 선언해야

[편집] 간단한 해결책은 당신의 결과를 필요로하지 않는 한, 재귀 호출에 count-1을 asign하는 것입니다 귀하의 경우 count-- 나중에

0

비 -로컬 변수는 블록으로 할당 할 수 없습니다.

그러나, __block을 만드는 것은 아마도 원하는 것이 아닙니다. 메소드 이름 runAction:completion:은 작업 완료 후 "완료"블록을 한 번 호출하는 것처럼 들립니다. 한번 호출되기 때문에 이후에 count이 사용되지 않으므로 사후 감쇄는 무의미합니다.

관련 문제