LoginSignup
16
20

More than 5 years have passed since last update.

swiftでexpected declarationとエラーが出る

Posted at

class ViewController: UIViewController {

}

の中に

for x in 0...5 {

}

と書いたらforのところにExpected declarationとエラーが出た

Expected declaration 

直訳 『予期された・期待された  宣言』

意味がわからない。 これを調べてみると

クラスに直接 処理を書いてはいけない
関数のなかで処理を書く

とのこと

クラスに書いていいのは
プロパティ...変数の宣言
メソッド・・・関数の宣言

処理を書くならメソッドの中ということか

16
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
20