ileitch
1
Hey all,
I'm trying to use swftc to typecheck very simple snippets of code, but I'm having an issue with @NSApplicationMain.
import AppKit
@NSApplicationMain
class ClassA: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {}
}
swiftc -sdk $(xcrun --show-sdk-path --sdk macosx) -typecheck test.swift
test.swift:3:1: error: 'NSApplicationMain' attribute cannot be used in a module that contains top-level code
@NSApplicationMain
^
test.swift:1:1: note: top-level code defined in this source file
import AppKit
^
Naming the file main.swift has no affect, and I don't see any compiler options that relate to entry points? What's the magic ingredient I'm missing here?
saagarjha
(Saagar Jha)
2
I believe this only works if you pass -parse-as-library to swiftc.
2 Likes
jrose
(Jordan Rose)
3
We should probably detect that while this file could have top-level code it doesn't in practice. Can you file a bug?
saagarjha
(Saagar Jha)
5
Just a quick head up: NSApplicationMain will call exit(1) if you don't have things like a valid Info.plist, etc. that are required for an application. Make sure they exist!