maartene
(Maarten Engels)
May 10, 2024, 2:03pm
1
Hi everyone,
Just wondering: is it possible to developer a SwiftUI App using only the Swift Package Manager? I.e. no .xcodeproj
?
I created an executable package, targeting macOS 14 only with a very simple scene/view:
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.padding()
}
}
This builds and runs, but does not show a window. So I'm wondering: is this even possible?
Kind regards,
Maarten
Yes, at least on macOS you can add this initializer to your App
type:
@main
struct MyApp: App {
init() {
DispatchQueue.main.async {
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
NSApp.windows.first?.makeKeyAndOrderFront(nil)
}
}
var body: some Scene {
// ...
}
}
12 Likes
maartene
(Maarten Engels)
May 10, 2024, 2:11pm
3
That's amazing! Thanks @Max_Desiatov
1 Like
kamcma
(Kyle McMahon)
May 13, 2024, 9:06pm
4
Depending on the APIs and entitlements you need, you could also create an "App Playground" project in Xcode and build and run it against a Catalyst destination. If you show the .swiftpm
package contents, you will see it is mostly a Swift package under the hood.
Depends how strictly you mean "only the SPM": only Xcode's fork of SPM brings in the AppleProductTypes module, I believe.
1 Like
maartene
(Maarten Engels)
May 14, 2024, 4:26am
5
My main objective is to use the simple modularization offered by SPM. And I’m only targeting macOS for now.
Note: I’m still using Xcode both as well as Viscose as the IDEs.
I haven’t encountered any issues so far, but also didn’t use any specific entitlements yet. Interesting to see where this goes.