2016-10-20 7 views
1

私は準備のための準備メソッドを使って変数xを渡しています。コードは以下の通りである:セグを準備してデータを渡す際にエラーが発生しました

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if (segue.identifier == "Restartseg") { 
     var x = 1 
     let destinationVC = segue.destination as! GameViewController 
     destinationVC.x = x 
    } 
    else if (segue.identifier == "Homeseg"){ 
     //pass more data 
    } 

} 

をしかしラインdestinationVC.x = xにコンパイル時にエラーが言うがされていますタイプの

値 'GameViewController' にはメンバーの 'x'

を持っていませんしかし、クラスidの下のゲームビューコントローラファイルでは、変数xを宣言しました。

class GameViewController: UIViewController { 
var x:Int! } 
+0

コードに問題はありません。きれいにして再構築してみてください。 –

答えて

0

変更この

let destinationVC = segue.destinationViewController as! GameViewController 

そして、クリーンにライン

let destinationVC = segue.destination as! GameViewController 

とプロジェクトをビルドします。うまくいきたいです

関連する問題