프로그래밍/SWIFT
[SWIFT] 'main' attribute cannot be used in a module contains top-level code
daewonyoon
2024. 4. 29. 17:49
반응형
xcode 에서 macos cli 어플리케이션을 swift 언어로 생성하고,
main.swift 에 다음과 같이 코딩했다.
import Foundation
@main
struct cli_test {
static func main() async {
print("Hello, World!")
}
}
@main 부분에 'main' attribute cannot be used in a moudle that contains top-level code 라는 빨간색 에러 메시지가 떴다.
검색하여, main.swift 의 이름을 다른 이름으로 바꾸어 ( myprogram.swift ) 준 이후에 에러가 사라졌다.
main.swift 안에 @main 이 오면 이 에러 메시지가 발생한다.
https://medium.com/@abedalkareemomreyh/what-is-main-in-swift-bc79fbee741c
What is @main in Swift
In all programs you always have an entry point, a place where your app should start from, and swift is no exception to that. If you…
medium.com
의 설명에 의하면 프로그램의 시작점은
- main.swift 파일
- @main 이 붙어 있는 class, struct, enum 안의 static main 함수.
- 등등
728x90