2017-02-23 5 views
-2

なぜそれが、私は、コードの行を持っている場合ということです。スウィフト単項演算エラー

Consecutive statements on a line must seperated with a ';' 

Unary operator '+' cannot be applied to an operand of type 'String' 

しかし、行はほぼ正確に同じで、編集中のラベルの別の名前以外は同じです。どんな助けもありがとう。

EDIT:

のフル機能:ラベルの

func checkValues() { 
    moneyLabel.text = "£" + String(moneyConstants.money) + ".00" 
    let savedValues = UserDefaults.standard 
    savedValues.setValue(moneyConstants.money, forKey: "money") 
    savedValues.setValue(buildingLevels.jitterClickNumber, forKey:"jitterClickBuildingLevel") 
    savedValues.setValue(buildingLevels.macrosNumber , forKey:"macrosBuildingLevel") 
    savedValues.setValue(buildingLevels.autoClickerNumber , forKey:"autoClickerBuildingLevel") 
    savedValues.setValue(buildingLevels.anotherPCNumber, forKey:"anotherPCBuildingLevel") 
    savedValues.setValue(buildingLevels.workerNumber , forKey:"workerBuildingLevel") 
    savedValues.setValue(buildingLevels.houseNumber , forKey:"houseBuildingLevel") 
    savedValues.setValue(buildingLevels.officeNumber , forKey:"officeBuildingLevel") 
    savedValues.setValue(buildingLevels.skyriseNumber , forKey:"skyriseBuildingLevel") 
    savedValues.setValue(buildingLevels.planetNuber , forKey:"planetBuildingLevel") 
    jitterClickCostLabel.text = "£" + String(buildingConstants.jitterClickConstantCost) + ".00" 
    macrosCostLabel.text = "£" + String(buildingConstants.macrosConstantCost) + ".00" 
    autoClickerCostLabel.text = "£" + String(buildingConstants.autoClickerConstantCost) + ".00" 
    anotherPCCostLabel.text = "£" + String(buildingConstants.anotherPCConstantCost) + ".00" 
    workerCostLabel.text = "£" + String(buildingConstants.workerConstantCost) + ".00" 
    houseCostLabel.text = "£" + String(buildingConstants.houseConstantCost) + ".00" 
    officeCostLabel.text = "£" + String(buildingConstants.officeConstantCost) + ".00" 
    skyriseCostLabel.text = "£" + String(buildingConstants.skyriseConstantCost) + ".00" 
    planetCostLabel.text = "£" + String(buildingConstants.planetConstantCost) + ".00" 
    moneyLabel.text = "£" + String(moneyConstants.money) + ".00" 
} 

宣言:

@IBOutlet var moneyLabel: UILabel! 
+1

* "ほぼ同じ" *は役に立たない、私たちは推測したくない。問題を示す*自己完結型*の例を投稿してください。 –

+0

@Martinどういう意味ですか?私は、私が言っている2つの行がまったく同じで、ラベルの変数名を変更するとエラーが発生する理由を理解できないと言っているだけです。 –

+1

問題が_前の行(または他の文脈)と関係していると思われます。問題の原因となっている_実際のコンテキスト_に実際のコード_を表示していない場合は、お手伝いできません。覚えておいて、私たちが知る必要があるかもしれないことを知らないので、周囲の文脈や 'moneyLabel'の宣言を含む十分な情報を表示してください。 – matt

答えて

1

私は問題は、プラス記号の後にスペースの不足によって引き起こされていると思われます、何らかの形であなたが私たちを見せてくれなかったのです。私はこのコードでまったく同じエラーメッセージを召喚することができます

func checkValues() { 
     let s = "2" +String(100) 
    } 

はここでエラーを示すスクリーンショットです:

enter image description here

だから私の推測では、あなたがそのような何かをやっているということです。

+0

しかし、私はどこでもそれをしていない –

+0

私はそれが推測だと言った。エラーを再現するのに十分な情報を与えられていません。一方、私はエラーをどのように得るかを正確に指示するスクリーンショットと共にコードを示しています。さあ、どうしたらいいのですか?show _me_どうやってエラーを出すのですか? – matt

関連する問題