Any idea how I could import SwiftUICharts framework only if the iOS version is over iOS 13? I added this framework via File > Swift Package > add package dependency. My app target has to be iOS 10.
I import this framework into a swiftui controller that will only show if the target is over iOS 14, so it's ok to use it there. But I don't know how. A simple @available doesn't work in this case.
EDIT. Here is my code:
AnalyticsNew controller:
#if !arch(arm)
import SwiftUI
@available(iOS 14, *)
struct AnalyticsNew: View {
var body: some View {
Home()
}
}
@available(iOS 14, *)
struct AnalyticsNew_Previews: PreviewProvider {
static var previews: some View {
AnalyticsNew()
}
}
@available(iOS 14, *)
struct Home : View {
//... some code
}
#endif
AnalyticsView controller that shoes the right controller depending on the iOS version:
#if canImport(SwiftUI)
import SwiftUI
#endif
import UIKit
class AnalyticsView: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let child = createViewController()
addChild(child)
child.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
child.view.frame = view.bounds
view.addSubview(child.view)
child.didMove(toParent: self)
}
func createViewController() -> UIViewController {
if #available(iOS 14, *) {
#if !arch(arm) //compatible SwiftUI IOS <10
return UIHostingController(rootView: AnalyticsNew())
#else
return AnalyticsOld()
#endif
} else {
return AnalyticsOld()
}
}
}