Skip to content

Commit f2cb9d0

Browse files
committed
Add the readme about backward deployment for CocoaPods and Carthage
1 parent edae2e2 commit f2cb9d0

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ For more information, it's really recommended to check our demo, to learn detail
213213

214214
### Common Problems
215215

216-
+ Using Image/WebImage/AnimatedImage in Button/NavigationLink
216+
#### Using Image/WebImage/AnimatedImage in Button/NavigationLink
217217

218218
SwiftUI's `Button` apply overlay to its content (except `Text`) by default, this is common mistake to write code like this, which cause strange behavior:
219219

@@ -251,6 +251,65 @@ NavigationView {
251251
}
252252
```
253253

254+
#### Use for backward deployment and weak linking SwiftUI
255+
256+
SDWebImageSwiftUI supports to use when your App Target has a deployment target version less than iOS 13/macOS 10.15/tvOS 13/watchOS 6. Which will weak linking of SwiftUI(Combine) to allows writing code with available check at runtime.
257+
258+
To use backward deployment, you have to do the follow things:
259+
260+
+ Add `-weak_framework SwiftUI -weak_framework Combine` in your App Target's `Other Linker Flags` build setting
261+
262+
You should notice that all the third party SwiftUI framework should have this build setting as well, not only just ourself (we already added). Or when running on iOS 12 device, it will trigger the runtime dyld error on startup.
263+
264+
+ Use CocoaPods or Carthage (SwiftPM does not support weak linking nor backward deployment currently)
265+
266+
For Carthage user, the built binary framework will use [Library Evolution](https://swift.org/blog/abi-stability-and-more/) to support for backward deployment.
267+
268+
For CocoaPods user, you should skip the platform validation in Podfile with
269+
270+
```ruby
271+
platform :ios, '13.0' # This does not effect your App Target's deployment target version, just a hint for CocoaPods
272+
```
273+
274+
+ Add **all the SwiftUI code** with the available annotation and runtime check, like this:
275+
276+
```swift
277+
// AppDelegate.swift
278+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
279+
// ...
280+
if #available(iOS 13, *) {
281+
window.rootViewController = UIHostingController(rootView: contentView)
282+
} else {
283+
window.rootViewController = ViewController()
284+
}
285+
// ...
286+
}
287+
288+
// ViewController.swift
289+
class ViewController: UIViewController {
290+
var label: UILabel = UILabel()
291+
override func viewDidLoad() {
292+
super.viewDidLoad()
293+
self.view.backgroundColor = .white
294+
self.view.addSubview(label)
295+
self.label.text = "Hello World iOS 12!"
296+
self.label.sizeToFit()
297+
self.label.center = self.view.center
298+
}
299+
}
300+
301+
// ContentView.swift
302+
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
303+
struct ContentView : View {
304+
var body: some View {
305+
Group {
306+
Text("Hello World iOS 13!")
307+
WebImage(url: URL(string: "https://i.loli.net/2019/09/24/rX2RkVWeGKIuJvc.jpg"))
308+
}
309+
}
310+
}
311+
```
312+
254313
## Demo
255314

256315
To run the example using SwiftUI, following the steps:

0 commit comments

Comments
 (0)