草庐IT

multithreading - Swift dispatch_after throwing is not a prefix unary operator 错误

coder 2023-09-12 原文

我有以下代码:

import SpriteKit
import Foundation

class GameScene: SKScene {
    var occupiedCoordinates: NSMutableArray = NSMutableArray()

    func addShape () {

        //...

        shape.position = CGPoint(x:actualX, y:actualY)
        self.occupiedCoordinates.addObject(NSValue(CGPoint:shape.position))
        let halfDuration = random(min: CGFloat(0.5), max: CGFloat(5))

        //...

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2*halfDuration), dispatch_get_main_queue(), ^{
            self.occupiedCoordinates.removeObjectAtIndex(0)
            });
    }

}

我使用了原始片段 GCD: Dispatch After 并且我在 dispatch_after() 行中得到以下消息

'^' is not a prefix unary operator

知道问题出在哪里吗?

最佳答案

^{...} 是 Objective-C 语法。您不需要 ^

关于multithreading - Swift dispatch_after throwing is not a prefix unary operator 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26285140/

有关multithreading - Swift dispatch_after throwing is not a prefix unary operator 错误的更多相关文章

随机推荐