{"id":333228,"date":"2022-05-17T15:00:33","date_gmt":"2022-05-17T15:00:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=333228"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=333228","title":{"rendered":"<span>\u041a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0446\u0438\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043f\u043e \u0432\u044c\u044e \u0432 SwiftUI \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 Flow Coordinator<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7fe\/638\/f88\/7fe638f88eabef7cda7ab3afd6482da0.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7fe\/638\/f88\/7fe638f88eabef7cda7ab3afd6482da0.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d Flow Coordinator (\u0434\u0430\u043b\u0435\u0435 \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440) \u0432 SwiftUI, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043e\u0442 \u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412 UIKit \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u0431\u044b\u043b \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0435\u043d &#8212; \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0432\u044c\u044e-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b (view controller), \u043e\u0442\u0434\u0435\u043b\u044f\u044f \u044d\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u0442 \u043a\u043e\u0434\u0430 \u0432\u044c\u044e-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0438 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u0435\u0439 (view model). \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u043e \u0432\u044c\u044e-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043a\u043e\u0434, \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0441\u0430\u043c\u0443 \u0432\u044c\u044e\u0445\u0443, \u0438 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044e, \u0447\u0442\u043e \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u201c\u043f\u043e\u0442\u043e\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u201d (\u0442\u043e\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u0444\u043b\u043e\u0443).<\/p>\n<p>\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0432 SwiftUI.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0b5\/f1d\/3bb\/0b5f1d3bbd4420dc24b954e82f190e67.png\" width=\"1400\" height=\"703\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0b5\/f1d\/3bb\/0b5f1d3bbd4420dc24b954e82f190e67.png\"\/><figcaption><\/figcaption><\/figure>\n<ol>\n<li>\n<p><strong>\u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0432 SwiftUI<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>\u0411\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0432 SwiftUI \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>@Binding<\/code>, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0432\u044c\u044e\u0445 SwiftUI, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <code>fullScreenCover<\/code>,<strong> <\/strong><code>sheet<\/code>,<strong> <\/strong><code>alert<\/code>,<strong> <\/strong><code>confirmationDialog<\/code> \u0438\u043b\u0438 <code>NavigationLink<\/code>:<\/p>\n<pre><code>NavigationLink( \u201cPurple\u201d, destination: ColorDetail(color: .purple), isActive: $shouldShowPurple) NavigationLink(tag: .firstLink, selection: activeLink, destination: firstDestination) { EmptyView() }<\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043e\u043d \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e:  <\/p>\n<pre><code>view .sheet(isPresented: $isShowingSheet, onDismiss: didDismiss) {    Text(\u201cLicense Agreement\u201d)  }  view.sheet(item: sheetItem, content: sheetContent)<\/code><\/pre>\n<p><strong>2. \u0412\u044c\u044e \u0438 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c\u00a0<\/strong><\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043c\u044b \u043e\u0442\u0434\u0435\u043b\u044f\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u044c\u044e \u043e\u0442 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 (\u0438\u043b\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044c\u044e) \u043f\u0443\u0442\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u043d\u0430 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u044c\u044e (View) \u0438 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c (ViewModel).<\/p>\n<p>\u0412\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u044c\u044e (\u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435) \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u043a\u0448\u0435\u043d\u044b, \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u0435 \u0438\u0437 \u0432\u044c\u044e (\u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435).<\/p>\n<p>\u0412\u044c\u044e \u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0438\u0445 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0435 \u0432\u044c\u044e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>struct ContentView&lt;VM: ContentViewModelProtocol>: View {      @StateObject var viewModel: VM      var body: some View {         ZStack {             Color.white.ignoresSafeArea()              VStack {                 Text(viewModel.text)                  Button(\"First view >\", action: viewModel.firstAction)             }         }         .navigationBarTitle(\"Title\", displayMode: .inline)     } }<\/code><\/pre>\n<p>\u0412\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u044c\u044e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c firstAction \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>protocol ContentViewModelProtocol: ObservableObject {     var text: String { get }      func firstAction() }  final class ContentViewModel: ContentViewModelProtocol {      let text: String = \"Content View\"      init() { }      func firstAction() {         \/\/ handle action     } }<\/code><\/pre>\n<p><strong>3. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440<\/strong><\/p>\n<p>\u0412 SwiftUI, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u0432\u0441\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0432\u044c\u044e. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044b \u043e \u043d\u0430\u0448\u0438\u0445 \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0430\u0445:<\/p>\n<p>1. \u0424\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u0432\u044c\u044e.<\/p>\n<p>2. \u0423 \u043d\u0430\u0441 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430.<\/p>\n<p>3. \u0421\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0443 \u0438\u0437 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>4. \u041d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u043e\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438.<\/p>\n<p><strong>3.1 \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0430\u00a0<\/strong><\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0438\u0437 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u043e \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440.<\/p>\n<pre><code>protocol ContentFlowStateProtocol: ObservableObject {     var activeLink: ContentLink? { get set } }<\/code><\/pre>\n<p><code>ContentLink<\/code> \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\/\u044d\u043a\u0448\u0435\u043d\u044b.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0430\u0448\u0435\u0439 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c\u044e. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u044d\u043a\u0448\u0435\u043d\u044b) \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0443 \u0447\u0435\u0440\u0435\u0437 <code>FlowStateProtocol<\/code>.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0448\u0430 \u043f\u043e\u043b\u043d\u0430\u044f <code>ContentViewModel<\/code>, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0430\u044f <code>ContentFlowStateProtocol<\/code>, \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>protocol ContentViewModelProtocol: ObservableObject {     var text: String { get }      func firstAction()     func secondAction()     func thirdAction()     func sheetAction() }  final class ContentViewModel: ContentViewModelProtocol, ContentFlowStateProtocol {      \/\/ MARK: - Flow State     @Published var activeLink: ContentLink?      \/\/ MARK: - View Model     let text: String = \"Content View\"      init() { }      func firstAction() {         activeLink = .firstLinkParametrized(text: \"Some param\")     }      func secondAction() {         activeLink = .secondLinkParametrized(number: 2)     }      func thirdAction() {         activeLink = .thirdLink     }      func sheetAction() {         activeLink = .sheetLink(item: \"Sheet param\")     } }<\/code><\/pre>\n<p><strong>3.2 \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f ContentLink \u0434\u043b\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u00a0<\/strong><\/p>\n<p>\u042d\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u043a\u0440\u0430\u043d\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u042d\u0442\u0438\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c \u043c\u043e\u0433\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <code>ContentLink<\/code> \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c <code>Identifiable<\/code> \u0438 <code>Hashable<\/code>.<\/p>\n<pre><code>enum ContentLink: Hashable, Identifiable {     case firstLink     case firstLinkParametrized(text: String)     case secondLink     case secondLinkParametrized(number: Int)     case thirdLink      case sheetLink(item: String)      var navigationLink: ContentLink {         switch self {         case .firstLinkParametrized:             return .firstLink         case .secondLinkParametrized:             return .secondLink         default:             return self         }     }      var sheetItem: ContentLink? {         switch self {         case .sheetLink:             return self         default:             return nil         }     }      var id: String {         switch self {         case .firstLink, .firstLinkParametrized:             return \"first\"         case .secondLink, .secondLinkParametrized:             return \"second\"         case .thirdLink:             return \"third\"         case let .sheetLink(item):             return item         }     } }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e <code>id<\/code> \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 <code>Identifiable<\/code>, <code>navigationLink<\/code> \u0434\u043b\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043a\u0435\u0439\u0441\u0430\u043c\u0438, <code>sheetLink<\/code> \u0434\u043b\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p><strong>3.3 \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u044c\u044e \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430<\/strong><\/p>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044c\u044e <code>ContentFlowCoordinator<\/code>. \u041e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043f\u043e \u044d\u043a\u0440\u0430\u043d\u0443.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440, \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438:<\/p>\n<pre><code>struct ContentFlowCoordinator&lt;State: ContentFlowStateProtocol, Content: View>: View {      @ObservedObject var state: State     let content: () -> Content      private var activeLink: Binding&lt;ContentLink?> {         $state.activeLink.map(get: { $0?.navigationLink }, set: { $0 })     }      private var sheetItem: Binding&lt;ContentLink?> {         $state.activeLink.map(get: { $0?.sheetItem }, set: { $0 })     }      var body: some View {         NavigationView {             ZStack {                 content()                     .sheet(item: sheetItem, content: sheetContent)                  navigationLinks             }         }         .navigationViewStyle(.stack)     }      @ViewBuilder private var navigationLinks: some View {         NavigationLink(tag: .firstLink, selection: activeLink, destination: firstDestination) { EmptyView() }         NavigationLink(tag: .secondLink, selection: activeLink, destination: secondDestination) { EmptyView() }         NavigationLink(tag: .thirdLink, selection: activeLink, destination: secondDestination) { EmptyView() }     }      private func firstDestination() -> some View {         var text: String?         if case let .firstLinkParametrized(param) = state.activeLink {             text = param         }          let viewModel = FirstViewModel(text: text)         let view = FirstView(viewModel: viewModel)         return view      }      private func secondDestination() -> some View {         var number: Int?         if case let .secondLinkParametrized(param) = state.activeLink {             number = param         }          let viewModel = SecondViewModel(number: number)         let view = SecondView(viewModel: viewModel)         return view     }      private func thirdDestination() -> some View {         let viewModel = ThirdViewModel()         let view = ThirdView(viewModel: viewModel)         return view     }      @ViewBuilder private func sheetContent(sheetItem: ContentLink) -> some View {         switch sheetItem {         case let .sheetLink(item):             SheetView(viewModel: SheetViewModel(text: item))         default:             EmptyView()         }     } }<\/code><\/pre>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0435\u0433\u043e <code>init<\/code> (\u0437\u0434\u0435\u0441\u044c \u043d\u0435\u044f\u0432\u043d\u0430\u044f) \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u043c\u0435\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438.<\/p>\n<p>1. <code>state<\/code> \u0442\u0438\u043f\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0433\u043e <code>ContentFlowStateProtocol<\/code>.<\/p>\n<p>2. <code>content<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 <code>@ViewBuilder<\/code> \u044d\u043a\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044c\u044e.<\/p>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445 <code>state<\/code> \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e \u043a\u0430\u043a <code>@ObservedObject<\/code> \u0438 \u043e\u043d\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c <code>@StateObject<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>ContentFlowStateProtocol<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f <code>ContentViewModel<\/code>, \u0438 \u044d\u0442\u0430 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0430 \u043a\u0430\u043a <code>@StateObject<\/code> \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u043d\u043e\u043c <code>ContentView<\/code>.<\/p>\n<p>\u0412-\u0442\u0440\u0435\u0442\u044c\u0438\u0445, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u043a \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u0434\u043b\u044f <code>NavigationLink<\/code>, \u0442.\u0435. <code>activeLink<\/code><strong>,<\/strong> \u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0442.\u0435. <code>sheetItem<\/code>.<\/p>\n<p>\u0412\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0442\u0435\u043b\u0430 <code>ContentFlowCoordinator<\/code>. \u0422\u0430\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 <code>NavigationView<\/code>, \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>navigationLinks<\/code> \u0438 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 <code>sheet(item:\u2026)<\/code>.<\/p>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u043d\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u0430\u0436\u043d\u043e\u0435: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c<strong> \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/strong> (factory functions), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043d\u0430\u0448\u0438 \u0432\u044c\u044e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\/\u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430. \u041e\u043d\u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u0441 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0439 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0430\u043c\u043e \u0432\u044c\u044e.<\/p>\n<p><strong>4. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0430 \u0441 \u0432\u044c\u044e<\/strong><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0430\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u044d\u043a\u0440\u0430\u043d\u0430 ContentView, \u2014 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u044c\u044e. \u042d\u0442\u043e \u0442\u043e \u0436\u0435 \u0432\u044c\u044e, \u0447\u0442\u043e \u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430, \u043d\u043e \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e <code>ContentFlowCoordinator<\/code> \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u0438, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>ContentFlowStateProtocol<\/code>.<\/p>\n<pre><code>struct ContentView&lt;VM: ContentViewModelProtocol &amp; ContentFlowStateProtocol>: View {      @StateObject var viewModel: VM      var body: some View {         ContentFlowCoordinator(state: viewModel, content: content)     }      @ViewBuilder private func content() -> some View {         ZStack {             Color.white.ignoresSafeArea()              VStack {                 Text(viewModel.text)                  Button(\"First view >\", action: viewModel.firstAction)                 Button(\"Second view >\", action: viewModel.secondAction)                 Button(\"Third view >\", action: viewModel.thirdAction)                 Button(\"Sheet view\", action: viewModel.sheetAction)             }         }         .navigationBarTitle(\"Title\", displayMode: .inline)     } }<\/code><\/pre>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u044d\u043a\u0448\u0435\u043d\u043e\u0432 \u0432 \u044d\u0442\u043e \u0432\u044c\u044e.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/20a\/b9a\/d57\/20ab9ad572b540a9efe14c1a25a67fbe.gif\" width=\"600\" height=\"1398\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/20a\/b9a\/d57\/20ab9ad572b540a9efe14c1a25a67fbe.gif\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0441\u0430\u043c\u0438\u043c \u043f\u043e\u0442\u0440\u043e\u0433\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0444\u043b\u043e\u0443-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0439\u0434\u044f <a href=\"https:\/\/https%20:\/\/github.com\/michzio\/FlowCoordinator-%D0%B2-SwiftUI\">\u043f\u043e \u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435<\/a> \u043d\u0430 \u043c\u043e\u0439 github.<\/p>\n<hr\/>\n<p>\u0412\u0438\u0434\u0436\u0435\u0442\u044b \u0432 iOS \u2014 \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u044f\u0440\u043a\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0438\u0432\u043b\u0435\u0447\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a \u0432\u0430\u0448\u0435\u043c\u0443 iOS \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u043d\u043e \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b. \u041c\u043d\u043e\u0433\u0438\u0435 \u043f\u0440\u043e \u043d\u0438\u0445 \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435 \u0443\u043c\u0435\u044e\u0442 \u0438\u0445 \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c. \u041f\u043e\u043a\u0430\u0436\u0435\u043c \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0438\u0434\u0436\u0435\u0442\u044b \u043d\u0430 SwiftUI, \u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430<a href=\"https:\/\/otus.pw\/HoTY\/\"> <strong>\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/strong><\/a> \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/company\/otus\/blog\/666220\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/666220\/<\/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<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d Flow Coordinator (\u0434\u0430\u043b\u0435\u0435 \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440) \u0432 SwiftUI, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043e\u0442 \u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412 UIKit \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u0431\u044b\u043b \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0435\u043d &#8212; \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0432\u044c\u044e-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b (view controller), \u043e\u0442\u0434\u0435\u043b\u044f\u044f \u044d\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u0442 \u043a\u043e\u0434\u0430 \u0432\u044c\u044e-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0438 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u0435\u0439 (view model). \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u043e \u0432\u044c\u044e-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043a\u043e\u0434, \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0441\u0430\u043c\u0443 \u0432\u044c\u044e\u0445\u0443, \u0438 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044e, \u0447\u0442\u043e \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u201c\u043f\u043e\u0442\u043e\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u201d (\u0442\u043e\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u0444\u043b\u043e\u0443).<\/p>\n<p>\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0432 SwiftUI.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<ol>\n<li>\n<p><strong>\u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0432 SwiftUI<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>\u0411\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0432 SwiftUI \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>@Binding<\/code>, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0432\u044c\u044e\u0445 SwiftUI, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <code>fullScreenCover<\/code>,<strong> <\/strong><code>sheet<\/code>,<strong> <\/strong><code>alert<\/code>,<strong> <\/strong><code>confirmationDialog<\/code> \u0438\u043b\u0438 <code>NavigationLink<\/code>:<\/p>\n<pre><code>NavigationLink( \u201cPurple\u201d, destination: ColorDetail(color: .purple), isActive: $shouldShowPurple) NavigationLink(tag: .firstLink, selection: activeLink, destination: firstDestination) { EmptyView() }<\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043e\u043d \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e:  <\/p>\n<pre><code>view .sheet(isPresented: $isShowingSheet, onDismiss: didDismiss) {    Text(\u201cLicense Agreement\u201d)  }  view.sheet(item: sheetItem, content: sheetContent)<\/code><\/pre>\n<p><strong>2. \u0412\u044c\u044e \u0438 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c\u00a0<\/strong><\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043c\u044b \u043e\u0442\u0434\u0435\u043b\u044f\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u044c\u044e \u043e\u0442 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 (\u0438\u043b\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044c\u044e) \u043f\u0443\u0442\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u043d\u0430 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u044c\u044e (View) \u0438 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c (ViewModel).<\/p>\n<p>\u0412\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u044c\u044e (\u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435) \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u043a\u0448\u0435\u043d\u044b, \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u0435 \u0438\u0437 \u0432\u044c\u044e (\u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435).<\/p>\n<p>\u0412\u044c\u044e \u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0438\u0445 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0435 \u0432\u044c\u044e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>struct ContentView&lt;VM: ContentViewModelProtocol>: View {      @StateObject var viewModel: VM      var body: some View {         ZStack {             Color.white.ignoresSafeArea()              VStack {                 Text(viewModel.text)                  Button(\"First view >\", action: viewModel.firstAction)             }         }         .navigationBarTitle(\"Title\", displayMode: .inline)     } }<\/code><\/pre>\n<p>\u0412\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u044c\u044e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c firstAction \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>protocol ContentViewModelProtocol: ObservableObject {     var text: String { get }      func firstAction() }  final class ContentViewModel: ContentViewModelProtocol {      let text: String = \"Content View\"      init() { }      func firstAction() {         \/\/ handle action     } }<\/code><\/pre>\n<p><strong>3. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440<\/strong><\/p>\n<p>\u0412 SwiftUI, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u0432\u0441\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0432\u044c\u044e. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044b \u043e \u043d\u0430\u0448\u0438\u0445 \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0430\u0445:<\/p>\n<p>1. \u0424\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u0432\u044c\u044e.<\/p>\n<p>2. \u0423 \u043d\u0430\u0441 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430.<\/p>\n<p>3. \u0421\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0443 \u0438\u0437 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>4. \u041d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u043e\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438.<\/p>\n<p><strong>3.1 \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0430\u00a0<\/strong><\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0438\u0437 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u043e \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440.<\/p>\n<pre><code>protocol ContentFlowStateProtocol: ObservableObject {     var activeLink: ContentLink? { get set } }<\/code><\/pre>\n<p><code>ContentLink<\/code> \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\/\u044d\u043a\u0448\u0435\u043d\u044b.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0430\u0448\u0435\u0439 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c\u044e. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u044d\u043a\u0448\u0435\u043d\u044b) \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0443 \u0447\u0435\u0440\u0435\u0437 <code>FlowStateProtocol<\/code>.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0448\u0430 \u043f\u043e\u043b\u043d\u0430\u044f <code>ContentViewModel<\/code>, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0430\u044f <code>ContentFlowStateProtocol<\/code>, \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>protocol ContentViewModelProtocol: ObservableObject {     var text: String { get }      func firstAction()     func secondAction()     func thirdAction()     func sheetAction() }  final class ContentViewModel: ContentViewModelProtocol, ContentFlowStateProtocol {      \/\/ MARK: - Flow State     @Published var activeLink: ContentLink?      \/\/ MARK: - View Model     let text: String = \"Content View\"      init() { }      func firstAction() {         activeLink = .firstLinkParametrized(text: \"Some param\")     }      func secondAction() {         activeLink = .secondLinkParametrized(number: 2)     }      func thirdAction() {         activeLink = .thirdLink     }      func sheetAction() {         activeLink = .sheetLink(item: \"Sheet param\")     } }<\/code><\/pre>\n<p><strong>3.2 \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f ContentLink \u0434\u043b\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u00a0<\/strong><\/p>\n<p>\u042d\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u043a\u0440\u0430\u043d\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u042d\u0442\u0438\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c \u043c\u043e\u0433\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <code>ContentLink<\/code> \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c <code>Identifiable<\/code> \u0438 <code>Hashable<\/code>.<\/p>\n<pre><code>enum ContentLink: Hashable, Identifiable {     case firstLink     case firstLinkParametrized(text: String)     case secondLink     case secondLinkParametrized(number: Int)     case thirdLink      case sheetLink(item: String)      var navigationLink: ContentLink {         switch self {         case .firstLinkParametrized:             return .firstLink         case .secondLinkParametrized:             return .secondLink         default:             return self         }     }      var sheetItem: ContentLink? {         switch self {         case .sheetLink:             return self         default:             return nil         }     }      var id: String {         switch self {         case .firstLink, .firstLinkParametrized:             return \"first\"         case .secondLink, .secondLinkParametrized:             return \"second\"         case .thirdLink:             return \"third\"         case let .sheetLink(item):             return item         }     } }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e <code>id<\/code> \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 <code>Identifiable<\/code>, <code>navigationLink<\/code> \u0434\u043b\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043a\u0435\u0439\u0441\u0430\u043c\u0438, <code>sheetLink<\/code> \u0434\u043b\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p><strong>3.3 \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u044c\u044e \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430<\/strong><\/p>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044c\u044e <code>ContentFlowCoordinator<\/code>. \u041e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043f\u043e \u044d\u043a\u0440\u0430\u043d\u0443.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440, \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438:<\/p>\n<pre><code>struct ContentFlowCoordinator&lt;State: ContentFlowStateProtocol, Content: View>: View {      @ObservedObject var state: State     let content: () -> Content      private var activeLink: Binding&lt;ContentLink?> {         $state.activeLink.map(get: { $0?.navigationLink }, set: { $0 })     }      private var sheetItem: Binding&lt;ContentLink?> {         $state.activeLink.map(get: { $0?.sheetItem }, set: { $0 })     }      var body: some View {         NavigationView {             ZStack {                 content()                     .sheet(item: sheetItem, content: sheetContent)                  navigationLinks             }         }         .navigationViewStyle(.stack)     }      @ViewBuilder private var navigationLinks: some View {         NavigationLink(tag: .firstLink, selection: activeLink, destination: firstDestination) { EmptyView() }         NavigationLink(tag: .secondLink, selection: activeLink, destination: secondDestination) { EmptyView() }         NavigationLink(tag: .thirdLink, selection: activeLink, destination: secondDestination) { EmptyView() }     }      private func firstDestination() -> some View {         var text: String?         if case let .firstLinkParametrized(param) = state.activeLink {             text = param         }          let viewModel = FirstViewModel(text: text)         let view = FirstView(viewModel: viewModel)         return view      }      private func secondDestination() -> some View {         var number: Int?         if case let .secondLinkParametrized(param) = state.activeLink {             number = param         }          let viewModel = SecondViewModel(number: number)         let view = SecondView(viewModel: viewModel)         return view     }      private func thirdDestination() -> some View {         let viewModel = ThirdViewModel()         let view = ThirdView(viewModel: viewModel)         return view     }      @ViewBuilder private func sheetContent(sheetItem: ContentLink) -> some View {         switch sheetItem {         case let .sheetLink(item):             SheetView(viewModel: SheetViewModel(text: item))         default:             EmptyView()         }     } }<\/code><\/pre>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0435\u0433\u043e <code>init<\/code> (\u0437\u0434\u0435\u0441\u044c \u043d\u0435\u044f\u0432\u043d\u0430\u044f) \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u043c\u0435\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438.<\/p>\n<p>1. <code>state<\/code> \u0442\u0438\u043f\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0433\u043e <code>ContentFlowStateProtocol<\/code>.<\/p>\n<p>2. <code>content<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 <code>@ViewBuilder<\/code> \u044d\u043a\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044c\u044e.<\/p>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445 <code>state<\/code> \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e \u043a\u0430\u043a <code>@ObservedObject<\/code> \u0438 \u043e\u043d\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c <code>@StateObject<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>ContentFlowStateProtocol<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f <code>ContentViewModel<\/code>, \u0438 \u044d\u0442\u0430 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0430 \u043a\u0430\u043a <code>@StateObject<\/code> \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u043d\u043e\u043c <code>ContentView<\/code>.<\/p>\n<p>\u0412-\u0442\u0440\u0435\u0442\u044c\u0438\u0445, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u043a \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u0434\u043b\u044f <code>NavigationLink<\/code>, \u0442.\u0435. <code>activeLink<\/code><strong>,<\/strong> \u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0442.\u0435. <code>sheetItem<\/code>.<\/p>\n<p>\u0412\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0442\u0435\u043b\u0430 <code>ContentFlowCoordinator<\/code>. \u0422\u0430\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 <code>NavigationView<\/code>, \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>navigationLinks<\/code> \u0438 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 <code>sheet(item:\u2026)<\/code>.<\/p>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u043d\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u0430\u0436\u043d\u043e\u0435: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c<strong> \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/strong> (factory functions), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043d\u0430\u0448\u0438 \u0432\u044c\u044e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\/\u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430. \u041e\u043d\u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u0441 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u044c \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0439 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0430\u043c\u043e \u0432\u044c\u044e.<\/p>\n<p><strong>4. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u043b\u043e\u0443-\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u043e\u0440\u0430 \u0441 \u0432\u044c\u044e<\/strong><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0430\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u044d\u043a\u0440\u0430\u043d\u0430 ContentView, \u2014 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u044c\u044e. \u042d\u0442\u043e \u0442\u043e \u0436\u0435 \u0432\u044c\u044e, \u0447\u0442\u043e \u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430, \u043d\u043e \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e <code>ContentFlowCoordinator<\/code> \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0432\u044c\u044e-\u043c\u043e\u0434\u0435\u043b\u0438, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>ContentFlowStateProtocol<\/code>.<\/p>\n<pre><code>struct ContentView&lt;VM:<\/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-333228","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/333228","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=333228"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/333228\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=333228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=333228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=333228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}