Reputation: 21
I'm trying to create a Swift application programmatically from the "Command Line Tool" template, and I can't solve the error No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file, exiting
.
Here are the steps I followed :
Create an "AppDelegate.swift" class, and delete the "main.swift" file.
Fill "AppDelegate.swift" with the following code:
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
}
Create a new group named "Supporting Files", and add a new "Property List" named "Info.plist".
In "Info.plist", add a row with the key "Principal class", of type "String", and write "NSApplication" in the Value column.
Register this property list in your project: In "Build Settings", in the "Packaging" part, edit the "Info.plist file" row and write appName/Info.plist
(appName must be changed according to your Project name).
Is there another thing to do to register this Info.plist file ?
Upvotes: 2
Views: 2180
Reputation: 118741
Your exact goal is unclear — Cocoa application bundles (which are actually folders containing the executable and supporting files) and "command-line"/non-GUI programs are different things. The @NSApplicationMain
attribute is intended for use only with full Cocoa applications.
Typically if you want to add an application to your project, you'd click the + button to add a new Cocoa Application target — but then Xcode will automatically create an Info.plist for you.
For a command-line program, however (as mentioned on this page and discussed in this question), you can simply put your code in a file called main.swift
;
Code written at global scope is used as the entry point for the program, so you don’t need a
main
function.
Upvotes: 1