Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing Pow conditionally on iOS 14 #25

Open
frogg opened this issue Mar 30, 2023 · 7 comments
Open

Importing Pow conditionally on iOS 14 #25

frogg opened this issue Mar 30, 2023 · 7 comments

Comments

@frogg
Copy link

frogg commented Mar 30, 2023

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:

image

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?

@robb
Copy link
Contributor

robb commented Mar 30, 2023

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.

@robb
Copy link
Contributor

robb commented Mar 30, 2023

Whoops1.

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.

Footnotes

  1. Hit send accidentally so I'm following up with a second comment

@robb robb changed the title Any idea how I can import this Package conditionally into a package that targets iOS 14? Importing Pow conditionally on iOS 14 Mar 30, 2023
@frogg
Copy link
Author

frogg commented Mar 30, 2023

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)

@robb
Copy link
Contributor

robb commented Mar 30, 2023

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.

@frogg
Copy link
Author

frogg commented Apr 12, 2023

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).

Screenshot 2023-04-12 at 23 29 46

@robb
Copy link
Contributor

robb commented Apr 13, 2023

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?

@frogg
Copy link
Author

frogg commented Sep 23, 2023

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.

image
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants