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

Set deployment target to iOS 11 #37

Merged
merged 1 commit into from
May 13, 2022
Merged

Set deployment target to iOS 11 #37

merged 1 commit into from
May 13, 2022

Conversation

DennisWeirauch
Copy link

Problem

Our project has deployment target iOS 12. Therefore we can't add Inject to our project using SPM.

Solution

Set minimum required version to iOS 11 (I found that in an earlier commit 63a7176) and add @available statements where needed.

@@ -2,6 +2,7 @@ import Foundation
import SwiftUI
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to guard even imports? since SwiftUI / Combine won't be available on iOS 11

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't know what the deployment target for SwiftUI or Combine (or any other of Apple's frameworks) actually is, but apparently it's low enough to be imported anywhere. That's why each type declaration in these frameworks has its own availability statement, like:

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public protocol View { ... }

So the frameworks can then be imported anywhere, but the types need to be guarded.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a #if canImport(SwiftUI) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canImport checks for platform availability, not deployment target. From the documentation:

The argument for the canImport() platform condition is the name of a module that may not be present on all platforms. This condition tests whether it’s possible to import the module, but doesn’t actually import it. If the module is present, the platform condition returns true; otherwise, it returns false.

So canImport(SwiftUI) will be true for all platforms that support SwiftUI.

But like I said, that's not required as Apple's frameworks don't have any deployment targets. So they can always be imported. Only the usage of types needs to be guarded then.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried it out in a sample project, where I set the deployment target to iOS 9 (oldest possible with Xcode 13.3.1).

The compiler only complains about missing availability statements. The imports are fine

Bildschirmfoto 2022-05-12 um 18 54 26

Once availability statements are added, the issues are resolved.

Bildschirmfoto 2022-05-12 um 18 54 37

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, thanks for confirming!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tvOS, macOS?

Copy link

@iandundas iandundas Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work in practice though - if you run it in an iOS 12 simulator it crashes at runtime:

dyld: Library not loaded: /System/Library/Frameworks/SwiftUI.framework/SwiftUI
  Referenced from: /Users/ian/Library/Developer/CoreSimulator/Devices/C9046621-63BE-4232-A98D-3DCB1FFA227B/data/Containers/Bundle/Application/AA85BE8E-39E6-49B3-A534-4D7FA99801B1/CTR.app/CTR
  Reason: image not found
dyld: launch, loading dependent libraries

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm back with a fix:

Just need to add -weak_framework SwiftUI to Other Linker Flags, and with that it runs iOS 12 with no issue.

@krzysztofzablocki krzysztofzablocki merged commit d229e83 into krzysztofzablocki:main May 13, 2022
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

Successfully merging this pull request may close these issues.

None yet

4 participants