Is Swiftui Backwards-Compatible With iOS 12.X and Older

Is SwiftUI backwards-compatible with iOS 12.x and older?

I just checked it out in Xcode 11 and can confirm it won't be backwards-compatible, as can be seen in SwiftUI's View implementation:

/// A piece of user interface.
///
/// You create custom views by declaring types that conform to the `View`
/// protocol. Implement the required `body` property to provide the content
/// and behavior for your custom view.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public protocol View : _View {

/// The type of view representing the body of this view.
///
/// When you create a custom view, Swift infers this type from your
/// implementation of the required `body` property.
associatedtype Body : View

/// Declares the content and behavior of this view.
var body: Self.Body { get }
}

SwiftUI on iOS 12 and below

SwiftUI is designed for iOS 13 (or higher in the future).
See SwiftUI Documentation, top right column SDKs.

dyld: Library not loaded SwiftUI when app runs on iOS 12 using @available(iOS 13.0, *)

Turns out this is a known issue and apple introduced a new build setting flag to handle it

Apps containing SwiftUI inside a Swift package might not run on
versions of iOS earlier than iOS 13. (53706729)

Workaround:

When back-deploying to an OS which doesn't contain the SwiftUI framework,
add the -weak_framework SwiftUI flag to the Other Linker Flags setting
in the Build Settings tab. See Frameworks and Weak Linking for more
information on weak linking a framework. This workaround doesn't apply
when using dynamically linked Swift packages which import SwiftUI.

Adding -weak_framework SwiftUI to Other Linker Flags fixed my issue

Is Swift 3 fully backwards compatible with previous OS versions

Every Swift app is shipped with the Swift standard library included. The advantage of this is that it can run on multiple OS versions by default. The negative point is that it adds a few MB to your final app bundle.

So yes, your app will work on previous versions but keep in mind that you can't submit apps to the Mac App Store until Xcode 8 GM will be released.

iOS SwiftUI - Cannot convert value of type ObservedObject

The ObservableObject is a reference type so we can just pass it by reference directly, binding is not needed.

struct CreateAccountButton : View {

let viewRouter: ViewRouter // << regular property

// if needed to observe it internally, ie. body (not closures)
// contains router's property usage

// @ObservedObject var viewRouter: ViewRouter


// ...

and call

CreateAccountButton(viewRouter: viewRouter) // inject reference

Trying to make iOS 13 project compatible with iOS 12

I'm using Xcode 10 for Swift 3 compatibility.

That’s the problem. You cannot mention iOS 13 classes using Xcode 10. It knows nothing about them. You must work entirely within Xcode 11 if you want to link against the iOS 13 SDK.



Related Topics



Leave a reply



Submit