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

标签 multithreading swift grand-central-dispatch dispatch

我有以下代码:

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/

相关文章:

c# - 在多线程环境中从 C# 调用 Delphi DLL 时发生访问冲突

swift - Firebase 管理下载 API 不可用

Java:如何创建一个 Stop JButton 来停止 Runnable() 线程?

swift - 如何修复错误 "deviceInputWithDevice is unavailable"?

ios - 快速无效计时器不起作用

ios - 我应该如何在 iOS 中使用 GCD dispatch_barrier_async(似乎在其他 block 之前而不是之后执行)

ios - 捕获的 self 在 dispatch_async 中被释放

swift - 核心数据: Inserting a new row after performing fetch

Android - 服务还是 IntentService?

java - 基于触发器java运行任务