Metal — it’s a proprietary graphics API made by Apple
Metal — it’s a proprietary graphics API made by Apple
Quartz is a layer beneath SwiftUI or AppKit. SwiftUI is still using Quartz under the hood. The way you use Quartz directly from SwiftUI vs AppKit is a bit different, though still fairly similar. A more fair comparison of the SwiftUI code would be:
struct HelloWorldView: View {
var body: some View {
Canvas { context, _ in
context.draw(
Text("HelloWorld")
.font(.system(size: 24))
.foregroundColor(.black),
at: CGPoint(x: 20, y: 20)
)
}
}
}
Alternatively an AppKit solution (not using Quartz directly) would be something like:
class HelloWorldView: NSView {
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
let text = NSAttributedString(
string: “Hello World”,
attributes: [.font: NSFont.systemFont(ofSize: 24), .foregroundColor: NSColor.black]
)
let label = NSTextField(labelWithAttributedString: text)
addSubview(label)
}
required init?(coder: NSCoder) {
fatalError()
}
}
In either AppKit or SwiftUI, you can access Quartz directly to implement custom views. However, most of the time the UI code you write in either SwiftUI or AppKit won’t call Quartz directly at all, but will instead be composed of built-in views, like (NS)TextField
or (NS)Button
. Under the hood, SwiftUI is mainly just using the AppKit components at the moment, but provides a significantly nicer way to use them (especially in regards to layout and data synchronization).
I don’t think Apple has every really had great backwards compatibility. Apple’s last PowerPC computers shipped in 2005, and in 2009 Snow Leopard released with no PowerPC support. That’s 4 years of upgrades, which is about the same as it is now for macOS.
Something to consider as well is learning both. Swift is certainly the best choice for making macOS/iOS GUIs. Other languages are probably better than Swift for your ML needs (could be rust, Python, etc.). However it’s totally possible to have an app using multiple languages. You could have the UI portion be in Swift, but the ML portions be in another language.
At my company we have a Mac app with the GUI written in Swift, shared logic with our Windows app written in C++, and some libraries written in Rust. So it’s certainly possible.
One caveat is that some languages don’t work with each other very well. Swift and Python do work well together iirc, so doing UI code in Swift and ML code in Python may not be a bad idea.
If you want to just stick to Swift, Apple does have some ML frameworks for Swift that you can use. I don’t do any work with ML, so I have no idea if these frameworks are any good, or have good resources for learning.
If you want to just stick with whatever language you use for ML, there are GUI libraries in nearly every language. These certainly won’t be as robust or as nice to work with as the native frameworks in Swift, but they could probably get the job done. I do know that a major issue with GUIs in Python is the difficulty in multi threading, which is a must for any app that performs long tasks without the UI freezing.
Happy to see those new options in Xcode 15. Those seem really useful.
Yeah not sure why Find Selected Symbol defaults to contains instead of matching. My search results get polluted with other symbols when I search for example MyStruct.image
and MyStruct
also has the property imageName
.
You can use swift package manager to create an executable target, which you can then run on macOS from the command line. Most frameworks (aside from UI) are shared between iOS and macOS like AVFoundation. If you don’t have access to macOS, you can still use swift package manager to build and run code on Linux or Windows, though you unfortunately won’t have access to any Apple frameworks.