Importing Pow conditionally on iOS 14
I would like to use Pow in a Swift Package supporting iOS 14:
platforms: [
.iOS(.v14)
],
I’ve tried to include the package using the condition parameter:
dependencies: [
.product(name: "Pow", package: "Pow", condition: .when(platforms: [.iOS(.v15), .macCatalyst]))
]
But somehow that doesn't work, Xcode is complaining like so:
Of course I’ll have to put these if #available(iOS 15.0, *) flags every time I use Pow code.
Any idea how to achieve this?
It seems that the platform here
platforms: [ .iOS(.v14) ]
is a different type (SupportedPlatform) compared to the the platform used here (PackageDescription.Platform):
.product(name: "Pow", package: "Pow", condition: .when(platforms: [.iOS(.v15), .macCatalyst]))
The latter doesn't seem to take a version parameter. However, TargetDependencyCondition also doesn't seem to offer anything else, like a condition based on a build parameter for example.
Whoops[^1].
From skimming through the forum, it seems like this is a problem in SPM that has been flagged before (although with slightly different usecases), so I'm not sure there's a solution here 😔.
Let me know if you'd like a refund.
[^1]: Hit send accidentally so I'm following up with a second comment
Thanks for looking into this, Robb!
I thought this might be a limitation of SPM because I couldn't really find a solution, so definitely not an issue with Pow! Decided to file an issue here in case you knew a workaround.
I’ll still have use-cases for this though, and happy to support this project!
What I dont really understand is why I can include Pow in an Xcode App project targeting iOS 14, and then conditionally use the framework (but not do the same in a Swift Package @Apple 👀):
import Pow
extension View {
func conditionalShineRepetitionEffectiOS16() -> some View {
if #available(iOS 16.0, *) {
return self.conditionalEffect(.repeat(.shine, every: .seconds(2)), condition: true)
} else {
return self
}
}
}
(also, I dont really like this workaround, it complicates the code (but it works!). Would be great to have an .available(…) modifier at some point…but that’s also feedback in the direction of Apple)
I’ll still have use-cases for this though, and happy to support this project!
Thanks, I appreciate it!
What I dont really understand is why I can include Pow in an Xcode App project targeting iOS 14, and then conditionally use the framework (but not do the same in a Swift Package https://github.com/apple 👀):
I think that's because SPM resolves the dependencies just once when you pull them whereas in an App project, you just call methods at runtime (which the #available makes sure actually exist).
I definitely agree on the workaround being a pain, (see also to #22), conditionally invoking view modifiers based on availability is a pain with SwiftUIs chaining syntax.
Hey Robb, not sure if there’s a fix for that, but I noticed that my app is now crashing on iOS 14.4 and earlier because the AVFAudio framework is missing (and somehow Pow tries to import it even though I’m just making use of Pow conditionally).
Hmm, AVFAudio was introduced in 14.5 and since Pow's deployment target is 15, it's not weak-linked?
Are you using SoundEffect in your iOS 15 code?
Hey Robb, coming back to this today.
Do you know how I can weak-link Pow to my project so that the app can still run on iOS 14?
I’ve tried to make the Link optional, but it’s still crashing with the same error message on iOS 14.
dyld: Library not loaded: /System/Library/Frameworks/AVFAudio.framework/AVFAudio
Referenced from: /Users/frederik/Library/Developer/Xcode/DerivedData/one_sec/Build/Products/Debug-iphonesimulator/Pow.framework/Pow
Reason: image not found
I dont use SoundEffect in my code btw to answer your previous question.