所以我完成了一個項目,當我跑它,它死機了,我得到了主題1:信號SIGABRT錯誤,我看了看說明,它給了我:Swift SpriteKit:線程1:信號SIGABRT。無法投射SKLabelNode類型的值?
無法投類型的值'SKLabelNode'(0x108ed0b78)改爲'Koala_Hop.MCTPointLabel'(0x108091da0)。 (LLDB)
此行的代碼:
func loadHighscore() {
let defaults = NSUserDefaults.standardUserDefaults()
let highscoreLabel = childNodeWithName("highscoreLabel") as! MCTPointLabel //line with error
highscoreLabel.setTo(defaults.integerForKey("highscore"))
真的很困惑,需要幫助搞清楚了這一點!提前致謝!
**EDIT**: The declaration of highscoreLabel:
func addPoints() {
let pointsLabel = MCTPointLabel(num: 0)
pointsLabel.fontColor = UIColor.brownColor()
pointsLabel.position = CGPointMake(30.0, view!.frame.size.height - 40)
pointsLabel.name = "pointsLabel"
addChild(pointsLabel)
let highScoreLabels = MCTPointLabel(num: 0)
highScoreLabels.position = CGPointMake(view!.frame.size.width - 40, view!.frame.size.height - 40)
addChild(highScoreLabels)
let highscoreLabel = SKLabelNode(text: "High Score")
highscoreLabel.fontColor = UIColor.brownColor()
highscoreLabel.fontSize = 16.0
highscoreLabel.fontName = "Chalkduster"
highscoreLabel.name = "highscoreLabel"
highscoreLabel.position = CGPointMake(620, 310)
addChild(highscoreLabel)
}
是類型MCTPointLabel名 「highscoreLabel」 的標籤? – MaxKargin
你是什麼意思? –
是MCTPointLabel類型的節點'highscoreLabel'?編譯器認爲它是'SKLabelNode' – MaxKargin