{"id":426919,"date":"2024-07-23T09:04:11","date_gmt":"2024-07-23T09:04:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=426919"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=426919","title":{"rendered":"<span>\u0421\u043a\u0440\u044b\u0442\u0430\u044f (\u043d\u0430 \u0432\u0438\u0434\u0443) \u0441\u0438\u043b\u0430 KeyPath&#8217;\u043e\u0432<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442. \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041c\u0430\u043a\u0441\u0438\u043c \u0427\u0435\u0440\u043d\u043e\u0443\u0441\u043e\u0432, \u0438 \u044f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0432 \u0420\u0430\u0439\u0444\u0435. \u042f \u043e\u0431\u043e\u0436\u0430\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u0438\u0437\u0430\u0439\u043d\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u043d\u044b\u0435 API. \u0410 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432 \u0434\u043b\u044f \u0445\u043e\u0440\u043e\u0448\u0438\u0445 API \u0432 Swift \u2014 \u044d\u0442\u043e KeyPath&#8217;\u044b. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043e \u043d\u0438\u0445 \u0438 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c.<\/p>\n<p>KeyPath`\u044b \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u043e\u0432\u0441\u0435\u043c\u0435\u0441\u0442\u043d\u043e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u0441 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0435 API.<\/p>\n<h3>\u041b\u0438\u043d\u0437\u044b<\/h3>\n<p>\u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a KeyPath&#8217;\u0430\u043c, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0438\u0445 \u043f\u0440\u0435\u0434\u0448\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, <br \/>\u043a\u0430\u043a \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043b\u0435\u0432\u044b\u0435 \u0432\u0435\u0449\u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043f\u0440\u0438\u0448\u043b\u0438 \u043a \u043d\u0430\u043c \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432. <\/p>\n<p>\u0420\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u043b\u0438\u043d\u0437\u0430\u0445. \u041a\u0430\u043a \u043c\u043d\u043e\u0433\u0438\u0435 \u0437\u043d\u0430\u044e\u0442, \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u043b\u044e\u0431\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432 \u043a\u043e\u0434\u0435 \u2014 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043b\u0438\u043d\u0437\u044b \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u044b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430: \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c, \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438 (let).<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u0434\u0432\u0438\u0436\u043e\u043a.<\/p>\n<pre><code class=\"swift\">enum Event { \/* ... *\/ } struct Vector {     let x: Double     let y: Double     let z: Double }    struct Player {     let location: Vector     let camera: Vector }    func getNewState(player: Player, event: Event) -> Player {     \/...\/ }<\/code><\/pre>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><code>Event<\/code> \u2014 \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0436\u0430\u043b \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443);<\/p>\n<\/li>\n<li>\n<p><code>Vector<\/code> \u2014 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441 \u0442\u0440\u0435\u043c\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043a\u0438 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0435\u043a\u0442\u043e\u0440;<\/p>\n<\/li>\n<li>\n<p><code>Player<\/code> \u2014 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0438\u0433\u0440\u043e\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0435\u0433\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 (<code>location<\/code>) \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u043c\u0435\u0440\u044b (<code>camera<\/code>);<\/p>\n<\/li>\n<li>\n<p><code>getNewState(player:event:)<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"swift\">enum Event {     case left     case right     \/...\/ }  func getNewState(player: Player, event: Event) -> Player {     switch event {     case .left:         Player(             location: Vector(                 x: player.location.x \u2014 1,                 y: player.location.y,                 z: player.location.z             ),             camera: player.camera         )     case .right:         Player(             location: Vector(                 x: player.location.x + 1,                 y: player.location.y,                 z: player.location.z             ),             camera: player.camera         )     } }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0418 \u0442\u0443\u0442 \u043d\u0430 \u0441\u0446\u0435\u043d\u0443 \u0432\u044b\u0445\u043e\u0434\u044f\u0442 \u043b\u0438\u043d\u0437\u044b.  <\/p>\n<pre><code class=\"swift\">struct Lens&lt;Root, Value> {     let get: (Root) -> Value     let set: (Root, Value) -> Root }<\/code><\/pre>\n<p>\u041b\u0438\u043d\u0437\u0430 \u2014 \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438, \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041e\u0434\u043d\u0430 \u2014 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0438\u043f\u0430 <code>Value<\/code> \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>Root<\/code>, \u0438 \u0434\u0440\u0443\u0433\u0430\u044f \u2014 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043d\u043e \u0438\u0437-\u0437\u0430 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>Root<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u0438\u043d\u0437\u0443 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0438\u0433\u0440\u043e\u043a\u0430:<\/p>\n<pre><code class=\"swift\">let locationXLens = Lens&lt;Player, Double>(     get: { $0.location.x },     set: { player, value in         Player(             location: Vector(                 x: value,                 y: player.location.y,                 z: player.location.z             ),             camera: player.camera         )     } )  func getNewState(player: Player, event: Event) -> Player {     switch event {     case .left: locationXLens.set(player, locationXLens.get(player) - 1)     case .right: locationXLens.set(player, locationXLens.get(player) + 1)     } }<\/code><\/pre>\n<p>\u0423\u0436\u0435 \u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u0441\u0430\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043b\u0438\u043d\u0437 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c:  <\/p>\n<pre><code class=\"swift\">extension Lens {     func compose&lt;NewValue>(         with other: Lens&lt;Value, NewValue>     ) -> Lens&lt;Root, NewValue> {         return .init(             get: { other.get(self.get($0)) },             set: { root, value in                 self.set(root, other.set(self.get(root), value))             }         )     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043b\u0438\u043d\u0437\u0443 \u043f\u043e\u0434 \u043a\u0430\u0436\u0434\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c.<\/p>\n<pre><code class=\"swift\">let player = Player(\/...\/)  let locationLens = Lens&lt;Player, Vector>(     get: { $0.location },     set: { player, location in Player(location: location, camera: player.camera) } )  let cameraLens = Lens&lt;Player, Vector>(     get: { $0.camera },     set: { player, camera in Player(location: player.location, camera: camera) } )  let xLens = Lens&lt;Vector, Double>(     get: { $0.x },     set: { vector, x in Vector(x: x, y: vector.y, z: vector.z) } )  \/\/ \u041b\u0438\u043d\u0437\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b x \u0438\u0437 \u043a\u0430\u043c\u0435\u0440\u044b \u0438\u0433\u0440\u043e\u043a\u0430 let cameraXLens = cameraLens.compose(with: xLens)  \/\/ \u041b\u0438\u043d\u0437\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b x \u0438\u0437 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u0433\u0440\u043e\u043a\u0430 let locationXLens = locationLens.compose(with: xLens)  let cameraX = cameraXLens.get(player) let newPlayer = locationXLens.set(player, locationXLens.get(player) + 1)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u0437\u043d\u0430\u043b\u0438 \u043f\u0440\u043e \u043b\u0438\u043d\u0437\u044b, \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e KeyPath&#8217;\u0430\u0445.  <\/p>\n<h3>KeyPaths<\/h3>\n<p>\u0412 \u044f\u0437\u044b\u043a\u0435 Swift KeyPath&#8217;\u044b, \u043f\u043e \u0441\u0443\u0442\u0438, \u0442\u0435 \u0436\u0435 \u043b\u0438\u043d\u0437\u044b (\u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 read-only). \u041e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b \u0442\u0438\u043f\u0430\u043c\u0438 <code>Root<\/code> \u0438 <code>Value<\/code> \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0447\u0438\u0442\u0430\u0442\u044c (\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c) \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 <code>Value<\/code> \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>Root<\/code>.<\/p>\n<p>KeyPath&#8217;\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0432\u0438\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"swift\">class AnyKeyPath: Hashable {}  class PartialKeyPath&lt;Root>: AnyKeyPath {}  class KeyPath&lt;Root, Value>: PartialKeyPath&lt;Root> {}  class WritableKeyPath&lt;Root, Value>: KeyPath&lt;Root, Value> {}  class ReferenceWritableKeyPath&lt;Root, Value>: WritableKeyPath&lt;Root, Value> {}<\/code><\/pre>\n<ul>\n<li>\n<p><code>AnyKeyPath<\/code> \u2014 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 KeyPath\u2019\u043e\u0432. \u041a\u0430\u043a \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u044d\u0442\u043e type-erased \u0432\u0435\u0440\u0441\u0438\u044f KeyPath&#8217;\u0430. \u041f\u043e\u0434\u043f\u0438\u0441\u0430\u043d \u043d\u0430 <code>Hashable<\/code>, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c KeyPath&#8217;\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u0445.<\/p>\n<\/li>\n<li>\n<p><code>PartialKeyPath&lt;Root><\/code> \u2014 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 type-erased \u0432\u0435\u0440\u0441\u0438\u044f, \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>Root<\/code>, \u043d\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 <code>Value<\/code>. \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e KeyPath\u2019\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0443\u0436\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043d\u043e \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u0438\u043f <code>Any<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>KeyPath&lt;Root, Value><\/code> \u2014 \u0441\u0430\u043c\u044b\u0439 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0442\u0438\u043f. \u0418\u043c\u0435\u0435\u0442 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0442\u0438\u043f\u044b-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u0422\u0430\u043a\u043e\u0439 KeyPath \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>Value<\/code> \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0438\u043f\u0430 <code>Root<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>WritableKeyPath&lt;Root, Value><\/code> \u2014 \u043a\u0430\u043a \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u0432\u0435\u0440\u0441\u0438\u044f KeyPath&#8217;\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043a\u0440\u043e\u043c\u0435 \u0447\u0442\u0435\u043d\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>ReferenceWritableKeyPath&lt;Root, Value><\/code> \u2014 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443, \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 reference \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u043e\u0439. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0435\u0441\u0442\u044c computed property, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0435\u0441\u0442\u044c <code>nonmutating set<\/code>, \u0442\u043e KeyPath \u043a \u0442\u0430\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u043e\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 <code>ReferenceWritable<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c KeyPath \u2014 \u044d\u0442\u043e KeyPath-\u043b\u0438\u0442\u0435\u0440\u0430\u043b:  <\/p>\n<pre><code class=\"swift\">let intDescriptionKeyPath = \\Int.description<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0442\u0438\u043f <code>Root<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u0435:  <\/p>\n<pre><code class=\"swift\">let d: KeyPath&lt;Int, String> = \\.description<\/code><\/pre>\n<p>\u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0432 Swift \u0435\u0441\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0430\u0431\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 (subscripts), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 KeyPath \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>Value<\/code>.  <\/p>\n<pre><code class=\"swift\">let int = 1 let anyKeyPathValue: Any? = int[keyPath: \\Int.description as AnyKeyPath] let partialKeyPathValue: Any = int[keyPath: \\.description as PartialKeyPath&lt;_>] let keyPathValue: String = int[keyPath: \\.description as KeyPath&lt;_, _>]<\/code><\/pre>\n<p>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e <code>WritableKeyPath<\/code> \u0438 <code>ReferenceWritableKeyPath<\/code> \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432.<\/p>\n<pre><code class=\"swift\">var globalInt = 0  struct Example { var int = 0 var global: Int { get { globalInt } nonmutating set { globalInt = newValue } } }  var mutableExample = Example()  print(mutableExample.int) \/\/ prints 0  mutableExample[keyPath: \\.int as WritableKeyPath&lt;_, _>] = 1 print(mutableExample.int) \/\/ prints 1  \/\/ \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 - \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u0430 (let) let immutableExample = Example() print(immutableExample.global) \/\/ prints 0  immutableExample[keyPath: \\.global as ReferenceWritableKeyPath&lt;_, _>] = 1 print(immutableExample.global) \/\/ prints 1<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c KeyPath&#8217;\u043e\u0432.  <\/p>\n<h3>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438  <\/h3>\n<p><strong>\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u044f KeyPath-\u043b\u0438\u0442\u0435\u0440\u0430\u043b\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/strong>  <\/p>\n<p>KeyPath-\u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code class=\"swift\">(Root) -> Value<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430.<\/p>\n<pre><code class=\"swift\">let array = [0, 1, 2] let arrayDescriptions = array.map(\\.description) \/\/ [\"0\", \"1\", \"2\"]<\/code><\/pre>\n<p><strong>Composability<\/strong><\/p>\n<p>KeyPath&#8217;\u044b, \u043a\u0430\u043a \u0438 \u043b\u0438\u043d\u0437\u044b, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>appending(path:)<\/code>.<\/p>\n<pre><code class=\"swift\">let intDescriptionKeyPath = \\Int.description let intWidthKeyPath = intDescriptionKeyPath.appending(path: \\.count)<\/code><\/pre>\n<p><strong>\u0414\u043e\u0441\u0442\u0443\u043f \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443<\/strong><\/p>\n<p>KeyPath&#8217;\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043b\u044e\u0431\u043e\u043c\u0443 \u0441\u0430\u0431\u0441\u043a\u0440\u0438\u043f\u0442\u0443 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u044d\u0442\u043e\u043c \u0441\u0430\u0431\u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u2014 <code>Hashable<\/code>.<\/p>\n<pre><code class=\"swift\">let arrayFirst: KeyPath&lt;[Int], Int?> = \\.first let arrayFirstUnwrapped: KeyPath&lt;[Int], Int> = \\.[0]<\/code><\/pre>\n<p><strong>\u0410\u0442\u0440\u0438\u0431\u0443\u0442 <\/strong><code><a class=\"mention\" href=\"\/users\/dynamicMemberLookup\">@dynamicMemberLookup<\/a><\/code><\/p>\n<p>\u0412 Swift \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0430\u0448\u0438\u0445 \u0442\u0438\u043f\u043e\u0432. \u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0430\u0431\u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<pre><code class=\"swift\">@dynamicMemberLookup enum JSON { case int case string \/* ... *\/  subscript(dynamicMember key: String) -> JSON? { \/* ... *\/ } }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u043e \u0438 KeyPath`\u044b.<\/p>\n<pre><code class=\"swift\">@dynamicMemberLookup struct Wrapper&lt;Wrapped> { var wrapped: Wrapped  subscript&lt;T>(dynamicMember keyPath: KeyPath&lt;Wrapped, T>) -> T { wrapped[keyPath: keyPath] }  subscript&lt;T>(dynamicMember keyPath: WritableKeyPath&lt;Wrapped, T>) -> T { get { wrapped[keyPath: keyPath] } set { wrapped[keyPath: keyPath] = newValue } }  subscript&lt;T>(dynamicMember keyPath: ReferenceWritableKeyPath&lt;Wrapped, T>) -> T { get { wrapped[keyPath: keyPath] } nonmutating set { wrapped[keyPath: keyPath] = newValue }  } }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u0443\u044e \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u0441\u0435\u043c \u0435\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c.  <\/p>\n<p><strong>Type Inference<\/strong><\/p>\n<p>Type Inference \u0434\u043b\u044f KeyPath&#8217;\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e, \u043a\u0430\u043a \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u2014 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0438\u043f\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435, \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u043e\u0439\u043c\u0435\u0442, \u043a\u0430\u043a\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 KeyPath.<\/p>\n<pre><code class=\"swift\">let someStrangeKeyPath = \\Int.description.count.description.count<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u043e\u043c, \u0433\u0434\u0435 KeyPath&#8217;\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f.  <\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<p><strong>\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 <\/strong><code><a class=\"mention\" href=\"\/users\/dynamicMemberLookup\">@dynamicMemberLookup<\/a><\/code><\/p>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0442 <code><a class=\"mention\" href=\"\/users\/dynamicMemberLookup\">@dynamicMemberLookup<\/a><\/code>, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435, \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u0442\u0438\u043f\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0440\u0430\u0437\u043e\u043c \u0438 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0438\u043b\u0438 \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u0435\u0449\u0435.<\/p>\n<pre><code class=\"swift\">public struct Dependencies { @TaskLocal static var current: Dependencies = .init( logger: .shared, analytics: .shared )  public var logger: Logger public var analytics: Analytics }  @dynamicMemberLookup  public protocol ViewModel: ObservableObject { \/* ... *\/ }  public extension ViewModel { subscript&lt;T>(dynamicMember keyPath: KeyPath&lt;Dependencies, T>) -> T { Dependencies.current[keyPath: keyPath] } }  @dynamicMemberLookup  public protocol NavigationHandler { \/* ... *\/ }  public extension NavigationHandler { subscript&lt;T>(dynamicMember keyPath: KeyPath&lt;Dependencies, T>) -> T { Dependencies.current[keyPath: keyPath] } }<\/code><\/pre>\n<p>\u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 view-\u043c\u043e\u0434\u0435\u043b\u0438 \u0438 NavigationHandler&#8217;\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0445 \u0438\u043b\u0438 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u0430\u043c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0410 \u0437\u0430 \u0441\u0447\u0435\u0442 <code>TaskLocal<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0438\u0445 \u0432 \u0442\u0435\u0441\u0442\u0430\u0445.<\/p>\n<pre><code class=\"swift\">final class VM: ViewModel {     func buttonTapped() {         self.logger.info(\"Tapped a button\")         self.analytics.send(\"Opening a screen\")     } }<\/code><\/pre>\n<h3>KeyPath&#8217;\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0430 \u043c\u0438\u043d\u0443\u0442\u0443, \u0447\u0442\u043e \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u044e \u0434\u0438\u0437\u0430\u0439\u043d-\u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0438 \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u044b \u0442\u043e\u043a\u0435\u043d\u044b, \u0434\u043b\u044f \u0446\u0432\u0435\u0442\u043e\u0432 \u043b\u0438, \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u0438\u043b\u0438 \u043a\u043b\u044e\u0447\u0435\u0439 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0435\u0432\u0430\u0436\u043d\u043e. <br \/>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0443\u0434\u0443\u0442 \u0446\u0432\u0435\u0442\u0430. \u0418\u0442\u0430\u043a, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c KeyPath`\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0434\u0438\u0437\u0430\u0439\u043d-\u0441\u0438\u0441\u0442\u0435\u043c\u0435.<\/p>\n<pre><code class=\"swift\">public struct ColorGuide { public struct Backgrounds { public let primary = Color.white public let secondary = Color.gray }  public var background: Backgrounds { .init() } }  public typealias ColorToken = KeyPath&lt;ColorGuide, Color><\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u0442\u0430\u043a\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e enum&#8217;\u043e\u0432:<\/p>\n<pre><code class=\"swift\">public enum ColorToken { public enum Background { case primary case secondary  var rawValue: Color { switch self { case .primary: .white case .secondary: .gray } } }  case background(Background) }<\/code><\/pre>\n<p>\u0423\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0443 KeyPath&#8217;\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u044c\u0448\u0435 \u043a\u043e\u0434\u0430, \u043e\u0434\u043d\u0430\u043a\u043e, \u0432\u0441\u0435 \u0432\u0435\u0441\u0435\u043b\u044c\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f.\u00a0<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"swift\">public struct OurButton: View { let text: String let color: ColorToken let action: () -> Void  public init( _ text: String, color: ColorToken, action: @escaping () -> Void ) { self.text = text self.color = color self.action = action }  public var body: some View { Button(text) { action() } .background(ColorGuide()[keyPath: color]) } }  public struct ButtonContainer: View { public struct Model { let text: String let color: ColorToken let action: () -> Void } let first: Model let second: Model?  public var body: some View { VStack { OurButton( first.text, color: first.color, action: first.action ) if let second { OurButton( second.text, color: second.color, action: second.action ) } } } }<\/code><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043a \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0434\u0438\u0437\u0430\u0439\u043d\u0435\u0440 \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u0432 <code>ButtonContainer<\/code> \u0432\u0442\u043e\u0440\u0430\u044f \u043a\u043d\u043e\u043f\u043a\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0435\u0435 \u0446\u0432\u0435\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f (\u0431\u044b\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c). \u041a\u0430\u043a \u043d\u0430\u043c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0446\u0432\u0435\u0442\u0443? <br \/>\u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e KeyPath&#8217;\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u0447\u0435\u0440\u0435\u0437 \u0441\u0430\u0431\u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"swift\">extension Color {     subscript(opacity value: Double) -> Color {         self.opacity(value)     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442:<\/p>\n<pre><code class=\"swift\">public struct ButtonContainer: View { \/* ... *\/ public var body: some View { VStack { OurButton(\/* ... *\/) if let second { OurButton( second.text, color: second.color.appdending(path: \\.[opacity: 0.85]), \/\/ &lt;&lt;&lt; action: second.action ) } } } }<\/code><\/pre>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<p>KeyPath&#8217;\u044b \u2014 \u0432\u0430\u0436\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 API. \u0417\u043d\u0430\u043d\u0438\u0435 \u0438\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0435, \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0435 \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 API, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438 \u0435\u0441\u0442\u044c \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u043c\u043e\u0435\u043c <a href=\"https:\/\/swiftaddict.com\/blog\/keypaths\">\u0441\u0430\u0439\u0442\u0435<\/a>. \u0414\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u044f\u043c\u0438!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/828896\/\"> https:\/\/habr.com\/ru\/articles\/828896\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442. \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041c\u0430\u043a\u0441\u0438\u043c \u0427\u0435\u0440\u043d\u043e\u0443\u0441\u043e\u0432, \u0438 \u044f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0432 \u0420\u0430\u0439\u0444\u0435. \u042f \u043e\u0431\u043e\u0436\u0430\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u0438\u0437\u0430\u0439\u043d\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u043d\u044b\u0435 API. \u0410 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432 \u0434\u043b\u044f \u0445\u043e\u0440\u043e\u0448\u0438\u0445 API \u0432 Swift \u2014 \u044d\u0442\u043e KeyPath&#8217;\u044b. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043e \u043d\u0438\u0445 \u0438 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c.<\/p>\n<p>KeyPath`\u044b \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u043e\u0432\u0441\u0435\u043c\u0435\u0441\u0442\u043d\u043e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u0441 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0435 API.<\/p>\n<h3>\u041b\u0438\u043d\u0437\u044b<\/h3>\n<p>\u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a KeyPath&#8217;\u0430\u043c, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0438\u0445 \u043f\u0440\u0435\u0434\u0448\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, <br \/>\u043a\u0430\u043a \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043b\u0435\u0432\u044b\u0435 \u0432\u0435\u0449\u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043f\u0440\u0438\u0448\u043b\u0438 \u043a \u043d\u0430\u043c \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432. <\/p>\n<p>\u0420\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u043b\u0438\u043d\u0437\u0430\u0445. \u041a\u0430\u043a \u043c\u043d\u043e\u0433\u0438\u0435 \u0437\u043d\u0430\u044e\u0442, \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u043b\u044e\u0431\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432 \u043a\u043e\u0434\u0435 \u2014 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043b\u0438\u043d\u0437\u044b \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u044b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430: \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c, \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438 (let).<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u0434\u0432\u0438\u0436\u043e\u043a.<\/p>\n<pre><code class=\"swift\">enum Event { \/* ... *\/ } struct Vector {     let x: Double     let y: Double     let z: Double }    struct Player {     let location: Vector     let camera: Vector }    func getNewState(player: Player, event: Event) -> Player {     \/...\/ }<\/code><\/pre>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><code>Event<\/code> \u2014 \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0436\u0430\u043b \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443);<\/p>\n<\/li>\n<li>\n<p><code>Vector<\/code> \u2014 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441 \u0442\u0440\u0435\u043c\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043a\u0438 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0435\u043a\u0442\u043e\u0440;<\/p>\n<\/li>\n<li>\n<p><code>Player<\/code> \u2014 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0438\u0433\u0440\u043e\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0435\u0433\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 (<code>location<\/code>) \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u043c\u0435\u0440\u044b (<code>camera<\/code>);<\/p>\n<\/li>\n<li>\n<p><code>getNewState(player:event:)<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"swift\">enum Event {     case left     case right     \/...\/ }  func getNewState(player: Player, event: Event) -> Player {     switch event {     case .left:         Player(             location: Vector(                 x: player.location.x \u2014 1,                 y: player.location.y,                 z: player.location.z             ),             camera: player.camera         )     case .right:         Player(             location: Vector(                 x: player.location.x + 1,                 y: player.location.y,                 z: player.location.z             ),             camera: player.camera         )     } }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0418 \u0442\u0443\u0442 \u043d\u0430 \u0441\u0446\u0435\u043d\u0443 \u0432\u044b\u0445\u043e\u0434\u044f\u0442 \u043b\u0438\u043d\u0437\u044b.  <\/p>\n<pre><code class=\"swift\">struct Lens&lt;Root, Value> {     let get: (Root) -> Value     let set: (Root, Value) -> Root }<\/code><\/pre>\n<p>\u041b\u0438\u043d\u0437\u0430 \u2014 \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438, \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041e\u0434\u043d\u0430 \u2014 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0438\u043f\u0430 <code>Value<\/code> \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>Root<\/code>, \u0438 \u0434\u0440\u0443\u0433\u0430\u044f \u2014 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043d\u043e \u0438\u0437-\u0437\u0430 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>Root<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u0438\u043d\u0437\u0443 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0438\u0433\u0440\u043e\u043a\u0430:<\/p>\n<pre><code class=\"swift\">let locationXLens = Lens&lt;Player, Double>(     get: { $0.location.x },     set: { player, value in         Player(             location: Vector(                 x: value,                 y: player.location.y,                 z: player.location.z             ),             camera: player.camera         )     } )  func getNewState(player: Player, event: Event) -> Player {     switch event {     case .left: locationXLens.set(player, locationXLens.get(player) - 1)     case .right: locationXLens.set(player, locationXLens.get(player) + 1)     } }<\/code><\/pre>\n<p>\u0423\u0436\u0435 \u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u0441\u0430\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043b\u0438\u043d\u0437 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c:  <\/p>\n<pre><code class=\"swift\">extension Lens {     func compose&lt;NewValue>(         with other: Lens&lt;Value, NewValue>     ) -> Lens&lt;Root, NewValue> {         return .init(             get: { other.get(self.get($0)) },             set: { root, value in                 self.set(root, other.set(self.get(root), value))             }         )     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043b\u0438\u043d\u0437\u0443 \u043f\u043e\u0434 \u043a\u0430\u0436\u0434\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c.<\/p>\n<pre><code class=\"swift\">let player = Player(\/...\/)  let locationLens = Lens&lt;Player, Vector>(     get: { $0.location },     set: { player, location in Player(location: location, camera: player.camera) } )  let cameraLens = Lens&lt;Player, Vector>(     get: { $0.camera },     set: { player, camera in Player(location: player.location, camera: camera) } )  let xLens = Lens&lt;Vector, Double>(     get: { $0.x },     set: { vector, x in Vector(x: x, y: vector.y, z: vector.z) } )  \/\/ \u041b\u0438\u043d\u0437\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b x \u0438\u0437 \u043a\u0430\u043c\u0435\u0440\u044b \u0438\u0433\u0440\u043e\u043a\u0430 let cameraXLens = cameraLens.compose(with: xLens)  \/\/ \u041b\u0438\u043d\u0437\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b x \u0438\u0437 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u0433\u0440\u043e\u043a\u0430 let locationXLens = locationLens.compose(with: xLens)  let cameraX = cameraXLens.get(player) let newPlayer = locationXLens.set(player, locationXLens.get(player) + 1)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u0437\u043d\u0430\u043b\u0438 \u043f\u0440\u043e \u043b\u0438\u043d\u0437\u044b, \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e KeyPath&#8217;\u0430\u0445.  <\/p>\n<h3>KeyPaths<\/h3>\n<p>\u0412 \u044f\u0437\u044b\u043a\u0435 Swift KeyPath&#8217;\u044b, \u043f\u043e \u0441\u0443\u0442\u0438, \u0442\u0435 \u0436\u0435 \u043b\u0438\u043d\u0437\u044b (\u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 read-only). \u041e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b \u0442\u0438\u043f\u0430\u043c\u0438 <code>Root<\/code> \u0438 <code>Value<\/code> \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0447\u0438\u0442\u0430\u0442\u044c (\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c) \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 <code>Value<\/code> \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>Root<\/code>.<\/p>\n<p>KeyPath&#8217;\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0432\u0438\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"swift\">class AnyKeyPath: Hashable {}  class PartialKeyPath&lt;Root>: AnyKeyPath {}  class KeyPath&lt;Root, Value>: PartialKeyPath&lt;Root> {}  class WritableKeyPath&lt;Root, Value>: KeyPath&lt;Root, Value> {}  class ReferenceWritableKeyPath&lt;Root, Value>: WritableKeyPath&lt;Root, Value> {}<\/code><\/pre>\n<ul>\n<li>\n<p><code>AnyKeyPath<\/code> \u2014 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 KeyPath\u2019\u043e\u0432. \u041a\u0430\u043a \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u044d\u0442\u043e type-erased \u0432\u0435\u0440\u0441\u0438\u044f KeyPath&#8217;\u0430. \u041f\u043e\u0434\u043f\u0438\u0441\u0430\u043d \u043d\u0430 <code>Hashable<\/code>, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c KeyPath&#8217;\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u0445.<\/p>\n<\/li>\n<li>\n<p><code>PartialKeyPath&lt;Root><\/code> \u2014 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 type-erased \u0432\u0435\u0440\u0441\u0438\u044f, \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>Root<\/code>, \u043d\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 <code>Value<\/code>. \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e KeyPath\u2019\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0443\u0436\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043d\u043e \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u0438\u043f <code>Any<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>KeyPath&lt;Root, Value><\/code> \u2014 \u0441\u0430\u043c\u044b\u0439 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0442\u0438\u043f. \u0418\u043c\u0435\u0435\u0442 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0442\u0438\u043f\u044b-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u0422\u0430\u043a\u043e\u0439 KeyPath \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>Value<\/code> \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0438\u043f\u0430 <code>Root<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>WritableKeyPath&lt;Root, Value><\/code> \u2014 \u043a\u0430\u043a \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u0432\u0435\u0440\u0441\u0438\u044f KeyPath&#8217;\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043a\u0440\u043e\u043c\u0435 \u0447\u0442\u0435\u043d\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>ReferenceWritableKeyPath&lt;Root, Value><\/code> \u2014 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443, \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 reference \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u043e\u0439. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0435\u0441\u0442\u044c computed property, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0435\u0441\u0442\u044c <code>nonmutating set<\/code>, \u0442\u043e KeyPath \u043a \u0442\u0430\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u043e\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 <code>ReferenceWritable<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c KeyPath \u2014 \u044d\u0442\u043e KeyPath-\u043b\u0438\u0442\u0435\u0440\u0430\u043b:  <\/p>\n<pre><code class=\"swift\">let intDescriptionKeyPath = \\Int.description<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0442\u0438\u043f <code>Root<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u0435:  <\/p>\n<pre><code class=\"swift\">let d: KeyPath&lt;Int, String> = \\.description<\/code><\/pre>\n<p>\u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0432 Swift \u0435\u0441\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0430\u0431\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 (subscripts), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 KeyPath \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>Value<\/code>.  <\/p>\n<pre><code class=\"swift\">let int = 1 let anyKeyPathValue: Any? = int[keyPath: \\Int.description as AnyKeyPath] let partialKeyPathValue: Any = int[keyPath: \\.description as PartialKeyPath&lt;_>] let keyPathValue: String = int[keyPath: \\.description as KeyPath&lt;_, _>]<\/code><\/pre>\n<p>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e <code>WritableKeyPath<\/code> \u0438 <code>ReferenceWritableKeyPath<\/code> \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432.<\/p>\n<pre><code class=\"swift\">var globalInt = 0  struct Example { var int = 0 var global: Int { get { globalInt } nonmutating set { globalInt = newValue } } }  var mutableExample = Example()  print(mutableExample.int) \/\/ prints 0  mutableExample[keyPath: \\.int as WritableKeyPath&lt;_, _>] = 1 print(mutableExample.int) \/\/ prints 1  \/\/ \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 - \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u0430 (let) let immutableExample = Example() print(immutableExample.global) \/\/ prints 0  immutableExample[keyPath: \\.global as ReferenceWritableKeyPath&lt;_, _>] = 1 print(immutableExample.global) \/\/ prints 1<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c KeyPath&#8217;\u043e\u0432.  <\/p>\n<h3>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438  <\/h3>\n<p><strong>\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u044f KeyPath-\u043b\u0438\u0442\u0435\u0440\u0430\u043b\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/strong>  <\/p>\n<p>KeyPath-\u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code class=\"swift\">(Root) -> Value<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430.<\/p>\n<pre><code class=\"swift\">let array = [0, 1, 2] let arrayDescriptions = array.map(\\.description) \/\/ [\"0\", \"1\", \"2\"]<\/code><\/pre>\n<p><strong>Composability<\/strong><\/p>\n<p>KeyPath&#8217;\u044b, \u043a\u0430\u043a \u0438 \u043b\u0438\u043d\u0437\u044b, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>appending(path:)<\/code>.<\/p>\n<pre><code class=\"swift\">let intDescriptionKeyPath = \\Int.description let intWidthKeyPath = intDescriptionKeyPath.appending(path: \\.count)<\/code><\/pre>\n<p><strong>\u0414\u043e\u0441\u0442\u0443\u043f \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443<\/strong><\/p>\n<p>KeyPath&#8217;\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043b\u044e\u0431\u043e\u043c\u0443 \u0441\u0430\u0431\u0441\u043a\u0440\u0438\u043f\u0442\u0443 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u044d\u0442\u043e\u043c \u0441\u0430\u0431\u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u2014 <code>Hashable<\/code>.<\/p>\n<pre><code class=\"swift\">let arrayFirst: KeyPath&lt;[Int], Int?> = \\.first let arrayFirstUnwrapped: KeyPath&lt;[Int], Int> = \\.[0]<\/code><\/pre>\n<p><strong>\u0410\u0442\u0440\u0438\u0431\u0443\u0442 <\/strong><code><a class=\"mention\" href=\"\/users\/dynamicMemberLookup\">@dynamicMemberLookup<\/a><\/code><\/p>\n<p>\u0412 Swift \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0430\u0448\u0438\u0445 \u0442\u0438\u043f\u043e\u0432. \u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0430\u0431\u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<pre><code class=\"swift\">@dynamicMemberLookup enum JSON { case int case string \/* ... *\/  subscript(dynamicMember key: String) -> JSON? { \/* ... *\/ } }<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u043e \u0438 KeyPath`\u044b.<\/p>\n<pre><code class=\"swift\">@dynamicMemberLookup struct Wrapper&lt;Wrapped> { var wrapped: Wrapped  subscript&lt;T>(dynamicMember keyPath: KeyPath&lt;Wrapped, T>) -> T { wrapped[keyPath: keyPath] }  subscript&lt;T>(dynamicMember keyPath: WritableKeyPath&lt;Wrapped, T>) -> T { get { wrapped[keyPath: keyPath] } set { wrapped[keyPath: keyPath] = newValue } }  subscript&lt;T>(dynamicMember keyPath: ReferenceWritableKeyPath&lt;Wrapped, T>) -> T { get { wrapped[keyPath: keyPath] } nonmutating set { wrapped[keyPath: keyPath] = newValue }  } }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u0443\u044e \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u0441\u0435\u043c \u0435\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c.  <\/p>\n<p><strong>Type Inference<\/strong><\/p>\n<p>Type Inference \u0434\u043b\u044f KeyPath&#8217;\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e, \u043a\u0430\u043a \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u2014 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0438\u043f\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435, \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u043e\u0439\u043c\u0435\u0442, \u043a\u0430\u043a\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 KeyPath.<\/p>\n<pre><code class=\"swift\">let someStrangeKeyPath = \\Int.description.count.description.count<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u043e\u043c, \u0433\u0434\u0435 KeyPath&#8217;\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f.  <\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<p><strong>\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 <\/strong><code><a class=\"mention\" href=\"\/users\/dynamicMemberLookup\">@dynamicMemberLookup<\/a><\/code><\/p>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0442 <code><a class=\"mention\" href=\"\/users\/dynamicMemberLookup\">@dynamicMemberLookup<\/a><\/code>, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435, \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u0442\u0438\u043f\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0440\u0430\u0437\u043e\u043c \u0438 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0438\u043b\u0438 \u043a\u0430\u043a-\u043b\u0438\u0431\u043e \u0435\u0449\u0435.<\/p>\n<pre><code class=\"swift\">public struct Dependencies { @TaskLocal static var current: Dependencies = .init( logger: .shared, analytics: .shared )  public var logger: Logger public var analytics: Analytics }  @dynamicMemberLookup  public protocol ViewModel: ObservableObject<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-426919","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/426919","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=426919"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/426919\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=426919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=426919"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=426919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}