[返回1%加速](https://hackmd.io/Y0CYS7ClTq2bWpKGcdvSwg)
# Combine & SwiftUI 目錄區
# Prerequisites
- [官方教學](https://developer.apple.com/tutorials/swiftui/creating-and-combining-views)
- [進入SwiftUI的世界](https://hackmd.io/@6b1GnQPKROaCguTG5hT6fQ/rkFRNA-yL)
- [SwiftUI入門導讀](https://icodesign.me/posts/swift-combine/)
- 官方
- 目前官方有實作combine, 包含URLSession、Timer、NotificationCenter、Entity...
```Swift
// urlsession publisher
let cancelable = URLSession.shared.dataTaskPublisher(for: URL(string: "https://httpbin.org/get?foo=bar")!)
.sink(receiveCompletion:{ _ in print("completion")},
receiveValue: { value in print((value.response as? HTTPURLResponse)?.statusCode)} )
)
```
**結果**

# Benefit
- 遵守PreviewProvider就可以即時預覽畫面
- 透過虛擬的UI層描述關係(不是實際渲染),將UI的變化與State做連動,這樣的好處是:
- 當 view 和 logic分離後, 可以更專注出 變數 的存取動向 (比起以往在class裡的 public private 對變數存取限制,更加清楚, 例如 當前 view使用的變數, 就用 @State、會給其他view用到就用@Enviroment,但在這的變數都是與view有關)
## Combine
- [Combine基礎](https://hackmd.io/@6b1GnQPKROaCguTG5hT6fQ/rJG6tabyI)
- [Combine ARC](https://medium.com/better-programming/swift-5-1-and-combine-memory-management-a-problem-14a3eb49f7ae)
### 事件流
- 有限事件流,使用Future,例如 網路抓資料,只會返回一次結果(包含成功或失敗)
- 無限事件流,可使用Subject,例如,使用者按下按鈕等等...
## SwiftUI
- [SwiftUI基礎](https://hackmd.io/@6b1GnQPKROaCguTG5hT6fQ/rJRkWAWk8)
- [HStack、VStack、ZStack](https://codeburst.io/playing-with-swiftui-part-3-76cae7514367)
- [UIKit接入SwiftUI](https://hackmd.io/@6b1GnQPKROaCguTG5hT6fQ/r17V36ZJU)
- [ViewModifier](https://programmingwithswift.com/viewmodifier-in-swiftui/)
- [移除在List(表格component)點選會出現highlight](https://stackoverflow.com/questions/56545444/how-to-remove-highlight-on-tap-of-list-with-swiftui)
- [Animation](https://swiftui-lab.com/swiftui-animations-part1/)
- [SwiftUI -> ViewController](https://stackoverflow.com/questions/59143053/how-to-execute-a-function-in-a-uiviewcontroller-through-a-swiftui-button)
## PropertyWrapper
- [參考1](https://medium.com/genetec-tech/property-wrappers-in-swift-5-1-the-missing-published-implementation-1a466ebcf660)
- [參考2](http://trycombine.com/posts/combine-property-wrappers/)
## 填坑
- [preview with initialize](https://hackmd.io/@6b1GnQPKROaCguTG5hT6fQ/BkNAd1Q1U)
## 自由共筆區
- [點我](https://hackmd.io/@6b1GnQPKROaCguTG5hT6fQ/Hy2O0a-kI)
其他資源
===
- [王巍](https://onevcat.com/2019/06/swift-ui-firstlook/)
- [heckj](https://heckj.github.io/swiftui-notes/)
- [hackingWithSwift](https://www.hackingwithswift.com/quick-start/swiftui)
- [CombineFetcher.swift](https://gist.github.com/stinger/7cb1a81facf7f846e3d53f60be34dd1e)
- [初識SwiftUI](https://www.twblogs.net/a/5d4ffe7cbd9eee5327fc96f2)
- [combine-property-wrappers](http://trycombine.com/posts/combine-property-wrappers/)
- [MVVM與SwiftUI](https://www.raywenderlich.com/4161005-mvvm-with-combine-tutorial-for-ios)
{"metaMigratedAt":"2023-06-15T02:49:01.790Z","metaMigratedFrom":"Content","title":"Combine & SwiftUI 目錄區","breaks":true,"contributors":"[{\"id\":\"e9bd469d-03ca-44e6-8282-e4c6e614fa7d\",\"add\":3687,\"del\":846}]"}