Flop-X Bond Flange Ebbe Bond Flange Schluter Bond Flange ...
Swift bond コードリーディング
-
Upload
shun-nakahara -
Category
Technology
-
view
556 -
download
0
Transcript of Swift bond コードリーディング
アジェンダ
● Reactive Programing とは
● Swift Bond とは
● Swift Bond のよく使うメソッド
● observe● EventProducer● Swift Bond を読んで気になった実装を紹介
Reactive Programming とは...時間や外部の入力とともに変化する値や計算を、ユーザ自身がプログラムするのでは
なく、システム(言語自体やライブラリ)がユーザからは見えないところで反応(reactive)してくれるというものです。
Swift Bond は...1. UI オブジェクトと ViewModel を繋いでデーターのやりとりをしてくれる
2. 繋いだデーターは Reactive な振る舞いを行ってくれる
3. 関数型プログラミングをサポート
4. UILabel や UITableView など標準なクラスを拡張して作られている
5. ジェネリクスや拡張などSwift の良い機能を使いまくっている
bidirectionalBindToEventProducerType:bidirectionalBindTo
※双方向に bind したい時に利用する
例)動的に値が変わった時に、入力欄も更新
その逆の、入力欄の値をユーザーが書き換えたらシステム上の値を更新
observeNewEventProducerType:observeNew
※データが更新された時に変更の値で何か処理を行いたい時に使用
例)動的に値が変わった時に、エラーチェックなどを行いたいなど
Wherespublic func bindTo<B : BindableType where B.Element == EventType> (bindable: B) -> DisposableType
public func bindTo<B : BindableType where B.Element == Optional<EventType>> (bindable: B) -> DisposableType
Phantom Typepublic func bindTo<B : BindableType where B.Element == EventType> (bindable: B) -> DisposableType
public func bindTo<B : BindableType where B.Element == Optional<EventType>> (bindable: B) -> DisposableType
NSRecursiveLock
private let lock = NSRecursiveLock(name: "com.xxx.yyyy")...lock.lock()...lock.unlock()
objc_setAssociatedObject
/** * Sets an associated value for a given object using a given key and association policy. * * @param object The source object for the association. * @param key The key for the association. * @param value The value to associate with the key key for object. Pass nil to clear an existing association. * @param policy The policy for the association. For possible values, see “Associative Object Behaviors.” * * @see objc_setAssociatedObject * @see objc_removeAssociatedObjects */@available(iOS 3.1, *)public func objc_setAssociatedObject( object: AnyObject!, _ key: UnsafePointer<Void>, _ value: AnyObject!, _ policy: objc_AssociationPolicy)
objc_getAssociatedObject
/** * Returns the value associated with a given object for a given key. * * @param object The source object for the association. * @param key The key for the association. * * @return The value associated with the key \e key for \e object. * * @see objc_setAssociatedObject */@available(iOS 3.1, *)public func objc_getAssociatedObject(object: AnyObject!, _ key: UnsafePointer<Void>) -> AnyObject!