2016-02-13 64 views
0

我一直工作在SpriteKit一個笨鳥先飛克隆,我不斷收到錯誤信號SIGABRT:主題1:SpriteKit斯威夫特

Thread 1: signal SIGABRT

對下面的代碼行。

class AppDelegate: UIResponder, UIApplicationDelegate 

看來,當這個代碼插入出現此錯誤:

_ = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: Selector("makePipes"), userInfo: nil, repeats: true) 

我環顧四周,在堆棧溢出和大多數的我發現並沒有涉及到SpriteKit的東西。我將如何擺脫這個錯誤?

+0

當你得到錯誤時,你能說控制檯中確切的錯誤是什麼嗎?您必須滾動瀏覽所有跟蹤行才能看到原始錯誤。 – creeperspeak

+0

我猜''makePipes'有問題。你可以發佈你的'makePipes'功能嗎? – creeperspeak

+0

確保'makePipes'方法存在且沒有參數,或者確實有參數(例如'sender:AnyObject'),請將'selector'參數改爲'Selector(「makePipes:」)'。 – 0x141E

回答

-1

使用Swift,您不需要使用Selector來定義選擇器,只需傳遞一個字符串即可。所以,你可以使用下面的:

NSTimer.scheduledTimerWithTimeInterval(3, target: self, 
     selector: "makePipes", userInfo: nil, repeats: true) 

這是假設makePipes沒有參數。如果它期望計時器作爲參數傳遞,則可以將其編碼爲"makePipes:"

+2

它可以使用或不使用'Selector()'。 – 0x141E