set property With type information (#keyPath( ) only return ‘Any’) Applicable to any type (#keyPath( ) only applicable to NSObjects) let keyPath = \UIView.frame view[keyPath: keyPath] \UIView.frame
set property With type information (#keyPath( ) only return ‘Any’) Applicable to any type (#keyPath( ) only applicable to NSObjects) let keyPath = \UIView.frame view[keyPath: keyPath] \UIView.frame
set property With type information (#keyPath( ) only return ‘Any’) Applicable to any type (#keyPath( ) only applicable to NSObjects) let keyPath = \UIView.frame view[keyPath: keyPath] let frame = view[keyPath: path] \UIView.frame
set property With type information (#keyPath( ) only return ‘Any’) Applicable to any type (#keyPath( ) only applicable to NSObjects) let keyPath = \UIView.frame view[keyPath: keyPath] let frame = view[keyPath: path] \UIView.frame //frame: CGRect
set property With type information (#keyPath( ) only return ‘Any’) Applicable to any type (#keyPath( ) only applicable to NSObjects) let keyPath = \UIView.frame view[keyPath: keyPath] let frame = view[keyPath: path] struct User { var id: Int } \UIView.frame //frame: CGRect
set property With type information (#keyPath( ) only return ‘Any’) Applicable to any type (#keyPath( ) only applicable to NSObjects) let keyPath = \UIView.frame view[keyPath: keyPath] let frame = view[keyPath: path] struct User { var id: Int } \User.id \UIView.frame //frame: CGRect
[] { guard let self = self as? ClassType else { continue } let target = self[keyPath: stash.keypath] let result = stash.condition(target) if result == false { return result } } return true }
.greaterThanOrEqual, to: view.heightAnchor, multiplier: 0.2) .setAnchor(\.centerXAnchor, .equal, to: view.centerXAnchor) .setAnchor(\.topAnchor, .equal, to: view.topAnchor) descLabel .setAnchor(\.widthAnchor, .equal, to: view.widthAnchor, multiplier: 0.2) .setAnchor(\.heightAnchor, .greaterThanOrEqual, to: view.heightAnchor) .setAnchor(\.centerXAnchor, .equal, to: view.centerXAnchor) .setAnchor(\.centerYAnchor, .equal, to: view.centerYAnchor)
set property with Type safety • Better Key-Value Coding for Swift • Create interface more flexible than ever (Compared with #KeyPath( ) ) • Easy to implement Fluent Interface!
Proposal SE-0252 https://github.com/apple/swift-evolution/blob/master/proposals/0252-keypath- dynamic-member-lookup.md Introduction to Swift Keypaths - Benedikt Terhechte http://www.swifttube.co/video/the-underestimated-power-of-keypaths The underestimated power of KeyPaths - Vincent Pradeilles http://www.swifttube.co/video/the-underestimated-power-of-keypaths FluentInterface https://martinfowler.com/bliki/FluentInterface.html Builder, Fluent Interface and classic builder https://medium.com/@sawomirkowalski/design-patterns-builder-fluent-interface- and-classic-builder-d16ad3e98f6c Reference
power of key paths in Swift - Sundell https://www.swiftbysundell.com/articles/the-power-of-key-paths-in-swift/ Using Swift KeyPaths for Beautiful User Preferences - Kane https://edit.theappbusiness.com/using-swift-keypaths-for-beautiful-user- preferences-c83c2f7ea7be More Information