swift錯誤 Expressions are not allowed at the top level

來源:互聯網
上載者:User

標籤:special   min   錯誤   檔案   files   ogr   long   是你   等等   

```

... earlier we said top-level code isn’t allowed in most of your app’s source files. The exception is a special file named “main.swift”, which behaves much like a playground file, but is built with your app’s source code. The “main.swift” file can contain top-level code, and the order-dependent rules apply as well. In effect, the first line of code to run in “main.swift” is implicitly defined as the main entrypoint for the program. This allows the minimal Swift program to be a single line — as long as that line is in “main.swift”.

```

原因就是你把print等等運算式放到其他檔案去了。在main.swift這個檔案中寫就沒問題

知道怎麼改就可以了。如果不滿足的話,可以看看上面這段官方代碼,寫得真好



文/把時間當做朋友(簡書作者)
原文連結:http://www.jianshu.com/p/6bc97afd9478
著作權歸作者所有,轉載請聯絡作者獲得授權,並標註“簡書作者”。

swift錯誤 Expressions are not allowed at the top level

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.