-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Conversation
@@ -2,6 +2,7 @@ import Foundation | |||
import SwiftUI |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, thanks for confirming!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tvOS, macOS?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.