Closed mickeyl closed 2 years ago
Hey @mickeyl
That's a great question, and no I haven't considered it until now. That being said, I see a lot of nice opportunities there. One advantage we have is reading the Xcodeproj file to generate the Shark.swift
file. So potentially we could detect what kind of application the target is (UIKit / AppKit) to generate the correct UIImage / NSImage
counterparts without having to do #if canImport(UIKit)
dances.
I'm not very experienced in AppKit so it'll need to do some exploration :)
Inspecting the buildSettings is certainly the first step towards an automatic detection of the target type. There is, e.g.,
SDKROOT = macosx;
and SDKROOT = iphoneos;
, respectively.
This will not help to detect SwiftUI though, which is my current playfield. SwiftUI has its own set of abstractions for colors and images and it builds targets for both iOS and macOS.
It looks like for a reliable auto-detection, we would need to query the source files and check whether @main
is used anywhere.
To be honest, I'm not so sure whether auto-detection is worth the hassle. It might be a better (and more simple) approach to just select the platform via a --platform
command line switch:
--platform UIKit
--platform AppKit
--platform SwiftUI
or
--platform iOS
--platform macOS
--platform SwiftUI
@mickeyl Hey sorry I seem to miss this command, but that's a great idea! As we're already reading the xcodeproj file, and require a target to work on, we can perhaps detect iOS / macOS and generate as such..
For SwiftUI though, perhaps there's no way to easily detect this as you said. There's also the case where the app uses a mix of (UIKit || AppKit) & SwiftUI. Let me explore whether having --platform
consume multiple options does the trick 😊
https://github.com/kaandedeoglu/Shark/tree/wip/framework-specific-code-generation now contains a preview of the code generation for AppKit
and SwiftUI
. Choose it by supplying the new --framework
option with appkit
, or swiftui
. I'd appreciate testing, in particular with the newly supported frameworks.
This has now merged to master and a new release (1.4.0) has been cut.
Did you ever consider adjusting Shark for AppKit?