ӳจͷΑ͏ͳߏจʹ / ҾΛίϯύΫτʹ Ͱ͖Δ class Label { var text = "" var fontSize = 12 } class ProductModel { var name = "kalupas" } let model = ProductModel() let label = Label()
Label ʹ ProductModel ͷ property Λ bind ͢Δ class Label { var text = "" var fontSize = 12 } class ProductModel { var name = "kalupas" } let model = ProductModel() let label = Label()
Label ʹ ProductModel ͷ property Λ bind ͢Δ class Label { var text = "" var fontSize = 12 } class ProductModel { var name = "kalupas" } let model = ProductModel() let label = Label() bind(model, \.name, to: label, \.text)
Label ʹ ProductModel ͷ property Λ bind ͢Δ class Label { var text = "" var fontSize = 12 } class ProductModel { var name = "kalupas" } let model = ProductModel() let label = Label() bind(model, \.name, to: label, \.text) • ӳจͷΑ͏ʹಡΊΔ • Bind model name to label text • getter, setter Λ؆ܿʹهड़Ͱ͖Δ • \.name = KeyPath (getter) • \.text = ReferenceWritableKeyPath (getterɾsetter)
enum ͷ associated value ΛऔΓग़͍ͨ࣌͠ (௨ৗ) enum Authentication { case authenticated(accessToken: String) case unauthenticated } let authentication = Authentication.authenticated( accessToken: "cafebeef" ) if case let .authenticated(accessToken) = authentication { // use accessToken }
enum ͷ associated value ΛऔΓग़͍ͨ࣌͠ (௨ৗ) enum Authentication { case authenticated(accessToken: String) case unauthenticated } let authentication = Authentication.authenticated( accessToken: "cafebeef" ) if case let .authenticated(accessToken) = authentication { // use accessToken }
Case Paths Λͬͯ associated value ΛೖΕΔ enum Authentication { case authenticated(accessToken: String) case unauthenticated } let authentication = Authentication.authenticated( accessToken: "cafebeef" )
Case Paths Λͬͯ associated value ΛೖΕΔ enum Authentication { case authenticated(accessToken: String) case unauthenticated } // let authentication = Authentication.authenticated( // accessToken: "cafebeef" // ) let authentication = (/Authentication.authenticated).embed("cafebeef")
Case Paths Ͱ associated value ΛऔΓग़͢ enum Authentication { case authenticated(accessToken: String) case unauthenticated } let authentication = (/Authentication.authenticated).embed(“cafebeef") if case let .authenticated(accessToken) = authentication { // use accessToken }
Case Paths Ͱ associated value ΛऔΓग़͢ enum Authentication { case authenticated(accessToken: String) case unauthenticated } let authentication = (/Authentication.authenticated).embed(“cafebeef") // if case let .authenticated(accessToken) = authentication { // // use accessToken // } (/Authentication.authenticated).extract(from: authentication)