Slide 1

Slide 1 text

ঢ়ଶ؅ཧͱ ϏϡʔσʔλόΠϯσΟϯά yohei SUGIGAMI 11/23 potatotips@FiNC

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Sync Messenger 8FC %FTLUPQ"QQ "OESPJE BOEJ04 ϏδωείϛϡχέʔγϣϯಛԽϝοηʔδϯάαʔϏε

Slide 4

Slide 4 text

Sync Messenger iOS 4XJGU .77. '31 1SPNJTF
 Ϟμϯͳཁૉٕज़Λશྗ౤ೖ

Slide 5

Slide 5 text

ΞϓϦͷίʔυ ෳࡶʹͳ͍ͬͯ·ͤΜ͔

Slide 6

Slide 6 text

ঢ়ଶͱUIελοΫͰ੔ཧ͠Α͏ )PXUPpYBCBEVTFSJOUFSGBDF ೔ຊޠ༁όου6*Λվળ͢Δํ๏ʕ6*ͷʮͭͷঢ়ଶʯΛߟ͑Δ w ϒϥϯΫεςʔτ w ϩʔσΟϯάεςʔτ w ύʔγϟϧεςʔτ w Τϥʔεςʔτ w ཧ૝εςʔτ ̍ը໘Ͱଟ༷ͳঢ়ଶͱΓɺͦΕʹ߹Θͤͨը໘Λ දࣔ͢ΔϩδοΫ͕ෳࡶͩͱίʔυ͕ΧΦεܥʹ

Slide 7

Slide 7 text

؅ཧͱ෼཭ ঢ়ଶΛ؅ཧ var state: State enum State { case Blank case Loading case Partial case Error case Ideal } 6*ελοΫຖʹϏϡʔΛ෦඼Խͯ͠෼཭ let blankView = BlankView() let loadingView = LoadingView() let partialView = PartialView() let errorView = ErrorView() let idealView = IdealView() or UITableView() etc … ͍ͩͿίʔυ੔ཧͰ͖ͦ͏

Slide 8

Slide 8 text

ঢ়ଶͱը໘ΛࣗಈͰ࿈ಈ͍ͨ͠ʂ ঢ়ଶ͕มΘΔͱ6*ελοΫͷදࣔ΋ ࿈ಈͯࣗ͠ಈͰը໘ͷදࣔ΋มߋ͍ͨ͠ state = .Blank blankView.hidden = false 㱺

Slide 9

Slide 9 text

ͦΕ ϏϡʔσʔλόΠϯσΟϯάͰʂ with SwiftBond

Slide 10

Slide 10 text

4UBUF3FRVFTUJOH 4UBUF&SSPS JUFNT<> 4UBUF/POF *OEJDBUPS7JFX 3FUSZ7JFX /P%BUB7JFX ViewDataBinding

Slide 11

Slide 11 text

ViewDataBinding 4UBUF3FRVFTUJOH 4UBUF&SSPS JUFNT<JUFN JUFN JUFN ʜ> 4UBUF/POF *OEJDBUPS7JFX 3FUSZ7JFX /P%BUB7JFX

Slide 12

Slide 12 text

Code with SwiftBond final class RequestListViewModel { let items: DynamicArray = DynamicArray([]) var requestListState = Dynamic(.None) var noDataFirstViewHidden: Dynamic { let a = indicatorViewHidden.map { $0 == false } let b = requestListFirstState.map { $0 == .Error } return reduce(a, b) { $0 || $1 == true } } var indicatorViewHidden: Dynamic { let a = requestListFirstState.map { $0 != RequestListState.Requesting } let b = items.map { count($0) > 0 } return reduce(a, b) { $0 || $1 == true } } var retryViewHidden: Dynamic { let a = requestListFirstState.map { $0 != RequestListState.Error } let b = items.map { count($0) > 0 } return reduce(a, b) { $0 || $1 == true } } 3FRVFTU4UBUFͱ*UFNTͷঢ়ଶͷΑΔڍಈΛએݴ


Slide 13

Slide 13 text

final class ContactsViewController: UIViewController { var tableViewDataSourceBond: UITableViewDataSourceBond! let viewModel = ContactsViewModel() let indicatorView = InstantiateFromNib(IndicatorView) let retryView = InstantiateFromNib(RetryView) let noDataView = InstantiateFromNib(NoDataView) override func viewDidLoad() { super.viewDidLoad() viewModel.requestList.indicatorViewHidden ->> indicatorView.dynHidden viewModel.requestList.retryViewHidden ->> retryView.dynHidden viewModel.requestList.noDataFirstViewHidden ->> noDataView.dynHidden } 7JFX$POUSPMMFSͰ7JFX.PEFMͷ4XJGU#POEͱ7JFXΛ#JOEJOH Code with SwiftBond

Slide 14

Slide 14 text

final class RequestListViewModel { typealias RequestTask = Task, NSError> func requestFirst(task: RequestTask) -> RequestTask { self.requestListState.value = .Requesting task.success { [weak self] (collection: ResponseCollection) -> Void in self?.items.setArray(collection.items) self?.requestListState.value = .None }.failure { [weak self] (errorInfo: RequestTask.ErrorInfo) -> Void in self?.requestListState.value = .Error } return task } 3FRVFTUͷ։࢝ɺਖ਼ৗ׬ྃɺҎ্׬ྃͰ4BUFΛߋ৽ ਖ਼ৗ׬ྃ࣌ʹJUFNTΛߋ৽ Code with SwiftBond

Slide 15

Slide 15 text

final class RequestListViewModel { lazy var stateChangedObserver = Bond { [weak self] state in switch state { case .Requesting: UIApplication.sharedApplication().networkActivityIndicatorVisible = true default: UIApplication.sharedApplication().networkActivityIndicatorVisible = false } } init() { requestListState ->| stateChangedObserver } OFUXPSL"DUJWJUZ*OEJDBUPS7JTJCMFΛ4UBUFͰ#JOEJOH Code with SwiftBond

Slide 16

Slide 16 text

·ͱΊ ɾΞϓϦΛঢ়ଶͱελοΫͰ؅ཧ ɾ͋Δঢ়ଶʹ͓͚Δը໘දࣔϩδοΫΛ ɹએݴతʹهड़ ɾঢ়ଶ͕มԽͨ͠Βࣗಈతʹը໘දࣔ΋ ɹมߋ͞ΕΔΑ͏ʹ

Slide 17

Slide 17 text

ߋʹৄࡉΛQiitaʹ΋ॻ͖·ͨ͠ IUUQRJJUBDPNTVTJFZZJUFNTBGCCEGG

Slide 18

Slide 18 text

Enjoy happy coding!