{"id":291458,"date":"2018-10-27T14:50:03","date_gmt":"2018-10-27T10:50:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=291458"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=291458","title":{"rendered":"Codable \u0434\u043b\u044f API \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043a\u0430\u043a \u043d\u0430\u0432\u0435\u0441\u0442\u0438 \u0432 \u043a\u043e\u0434\u0435 \u043f\u043e\u0440\u044f\u0434\u043e\u043a"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>  \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e Swift 4 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b Codable, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c\/\u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438. \u0412 \u043c\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f API \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0438 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0433\u043e\u0434 \u044f \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043b \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043a\u043e\u0434\u0430 \u0432\u043e \u0447\u0442\u043e-\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e\u0435, \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e\u0435 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0443\u0442\u0435\u043c \u0443\u0431\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043a\u043e\u0434\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Codable \u0434\u0430\u0436\u0435 \u0434\u043b\u044f multipart \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 url query \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0422\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0438\u0437 \u0441\u0435\u0431\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043d\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0430\u0441\u044c \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Vapor 3 \u043d\u0430 \u0431\u044d\u043a\u0435\u043d\u0434\u0435. \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430\u0437\u0430\u0434 \u044f \u0432\u044b\u0434\u0435\u043b\u0438\u043b \u0432\u0441\u0435 \u0441\u0432\u043e\u0438 \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438 \u043d\u0430\u0437\u0432\u0430\u043b \u0435\u0435 CodyFire. \u041e \u043d\u0435\u0439 \u043c\u043d\u0435 \u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440<\/h4>\n<p>  CodyFire \u0431\u0430\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 Alamofire, \u043d\u043e \u044d\u0442\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 Alamofire, \u044d\u0442\u043e \u0446\u0435\u043b\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 REST API \u0434\u043b\u044f iOS. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0435 \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u044e, \u0447\u0442\u043e \u0432 Alamofire \u043f\u0438\u043b\u044f\u0442 \u043f\u044f\u0442\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 Codable, \u0442.\u043a. \u044d\u0442\u043e \u043d\u0435 \u0443\u0431\u044c\u0435\u0442 \u043c\u043e\u0451 \u0442\u0432\u043e\u0440\u0435\u043d\u0438\u0435.<\/p>\n<h2>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u0434\u0430\u043b\u0435\u043a\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0442\u0440\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430: <\/p>\n<p>  <b>dev<\/b> \u2014 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0442\u043e \u0447\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0438\u0437 Xcode<br \/>  <b>stage<\/b> \u2014 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0434 \u0440\u0435\u043b\u0438\u0437\u043e\u043c, \u043e\u0431\u044b\u0447\u043d\u043e \u0432 TestFlight \u0438\u043b\u0438 InHouse<br \/>  <b>prod<\/b> \u2014 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d, \u0434\u043b\u044f AppStore<\/p>\n<p>  \u0418 \u043c\u043d\u043e\u0433\u0438\u0435 iOS \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0437\u043d\u0430\u044e\u0442 \u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438 <i>Environment Variables<\/i> \u0438 \u043e \u0441\u0445\u0435\u043c\u0430\u0445 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432 Xcode, \u043d\u043e \u0437\u0430 \u043c\u043e\u044e (8+ \u043b\u0435\u0442) \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443 90% \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0440\u0443\u043a\u0430\u043c\u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0435 \u043f\u043e\u043a\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u044e\u0442, \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0434 \u0441\u0431\u043e\u0440\u043a\u043e\u0439, \u0438 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0432 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u043d\u0430\u0434\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>  CodyFire \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432 \u043a\u0430\u043a\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0434\u0435\u043b\u0430\u0435\u0442 \u043e\u043d\u043e \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code>#if DEBUG     \/\/DEV environment #else     if Bundle.main.appStoreReceiptURL?.lastPathComponent == &quot;sandboxReceipt&quot; {         \/\/TESTFLIGHT environment     } else {         \/\/APPSTORE environment     } #endif <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c, \u0430 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432 AppDelegate \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0440\u0438 URL<\/p>\n<pre><code>import CodyFire  @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -&gt; Bool {         let dev = CodyFireEnvironment(baseURL: &quot;http:\/\/localhost:8080&quot;)         let testFlight = CodyFireEnvironment(baseURL: &quot;https:\/\/stage.myapi.com&quot;)         let appStore = CodyFireEnvironment(baseURL: &quot;https:\/\/api.myapi.com&quot;)         CodyFire.shared.configureEnvironments(dev: dev,                                                testFlight: testFlight,                                               appStore: appStore)         return true     } } <\/code><\/pre>\n<p>  \u0418 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>  \u041d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438 \u043d\u0430\u043c \u0447\u0430\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432 Xcode \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c dev, stage \u0438 prod \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u043f\u0440\u0438\u0437\u044b\u0432\u0430\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0445\u0435\u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/u_\/rp\/t_\/u_rpt_jk71avrzwwasrgviv7rgk.png\" alt=\"image\"\/>  <\/p>\n<blockquote><p><i>\u0421\u043e\u0432\u0435\u0442: \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <i>Manage schemes<\/i> \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0433\u0430\u043b\u043e\u0447\u043a\u0443 `shared` \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432\u0441\u0435\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/i><\/p><\/blockquote>\n<p>  \u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f `env` \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0442\u0440\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f: dev, testFlight, appStore.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ur\/j4\/ee\/urj4eeqtonszxwlo8uv-w8fdt4a.png\" alt=\"image\"\/><\/p>\n<p>  \u0418 \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u0438 \u0441\u0445\u0435\u043c\u044b \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 CodyFire \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0432 <i>AppDelegate.didFinishLaunchingWithOptions<\/i> \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 CodyFire<\/p>\n<pre><code>CodyFire.shared.setupEnvByProjectScheme()<\/code><\/pre>\n<p>  \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0447\u0430\u0441\u0442\u043e \u0431\u043e\u0441\u0441 \u0438\u043b\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u00ab\u043d\u0430 \u043b\u0435\u0442\u0443\u00bb \u0433\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0430 <i>LoginScreen<\/i>. \u0421 CodyFire \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u044f \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0438\u0437\u043c\u0435\u043d\u0438\u0432 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>CodyFire.shared.environmentMode = .appStore<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u0438 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b\u043e\u0441\u044c, \u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 <i>UserDefaults<\/i>, \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 <i>AppDelegate<\/i> \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0439\u0442\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435.<\/p><\/blockquote>\n<p> \u042d\u0442\u043e\u0442 \u0432\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u043e. \u0410 \u0437\u0430\u043e\u0434\u043d\u043e \u043c\u044b \u0443\u0436\u0435 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443.<\/p>\n<h2>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b<\/h2>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u043c\u043e\u0435\u043c \u0432\u0438\u0434\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0444\u0430\u0439\u043b\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 API \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0438\u0434\u0435\u043e\u043b\u043e\u0433\u0438\u0435\u0439 CodyFire.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u044d\u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/0f\/pn\/l8\/0fpnl8_sb2a6uhivnubvfwdgddy.png\" alt=\"image\"\/><\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0438 \u0444\u0430\u0439\u043b\u043e\u0432, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 <i>API.swift<\/i>.<\/p>\n<pre><code>class API {     typealias auth = AuthController     typealias post = PostController } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0432\u0441\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u043a\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 `API.controller.method`.<\/p>\n<pre><code>class AuthController {} <\/code><\/pre>\n<p>  <i>API+Login.swift<\/i><\/p>\n<pre><code>extension AuthController {     struct LoginResponse: Codable {         var token: String     }          static func login(email: String, password: String) -&gt; APIRequest&lt;LoginResponse&gt; {         return APIRequest(&quot;login&quot;).method(.post)                                   .basicAuth(email: email, password: password)                                   .addKnownError(.notFound, &quot;User not found&quot;)     } } <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0435 \u043c\u044b \u0434\u0435\u043a\u043b\u0430\u0440\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043d\u0430\u0448\u0435\u043c\u0443 API:<\/p>\n<p>   \u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c endpoint<br \/>   \u2014 HTTP \u043c\u0435\u0442\u043e\u0434 POST<br \/>   \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0440\u0430\u043f\u043f\u0435\u0440 \u0434\u043b\u044f basic auth<br \/>   \u2014 \u0434\u0435\u043a\u043b\u0430\u0440\u0438\u0438\u0440\u0443\u0435\u043c \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 (\u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e)<br \/>   \u2014 \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<p>  \u0427\u0442\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u043a\u0440\u044b\u0442\u044b\u043c?<\/p>\n<p>   \u2014 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 URL \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0442.\u043a. \u043e\u043d \u0443\u0436\u0435 \u0437\u0430\u0434\u0430\u043d \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e<br \/>   \u2014 \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <i>200 OK<\/i> \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e  <\/p>\n<blockquote><p>200 \u041e\u041a \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u0443\u0441 \u043a\u043e\u0434 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 CodyFire \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0438\u0434\u0435\u0442 \u0434\u0435\u043a\u043e\u0434\u0438\u043d\u0433 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f callback, \u0447\u0442\u043e \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e, \u0432\u043e\u0442 \u0432\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p><\/blockquote>\n<p> \u0414\u0430\u043b\u0435\u0435 \u0433\u0434\u0435-\u0442\u043e \u0432 \u043a\u043e\u0434\u0435 \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e <i>LoginScreen<\/i> \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c<\/p>\n<pre><code>API.auth.login(email: &quot;test@mail.com&quot;, password: &quot;qwerty&quot;).onKnownError { error in     switch error.code {     case .notFound: print(error.description) \/\/\u0432\u044b\u0432\u0435\u0434\u0435\u0442: User not found     default: print(error.description)     } }.onSuccess { token in     \/\/TODO: \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c auth token \u0432 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435     print(&quot;Received auth token: &quot;+ token) } <\/code><\/pre>\n<p>  <i>onKnownError<\/i> \u0438 <i>onSuccess<\/i> \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0430\u043b\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <i>APIRequest<\/i>, \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043d\u0438\u0445 \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>  \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 \u0432\u0445\u043e\u0434\u043e\u043c \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0432\u044b \u0438 \u0441\u0430\u043c\u0438 \u043c\u043e\u0433\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0438 \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u0440\u0430\u0432\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0444\u043e\u0440\u043c\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  <i>API+Signup.swift<\/i><\/p>\n<pre><code>extension AuthController {     struct SignupRequest: JSONPayload {         let email, password: String         let firstName, lastName, mobileNumber: String         init(email: String,              password: String,              firstName: String,               lastName: String,               mobileNumber: String) {             self.email = email             self.password = password             self.firstName = firstName             self.lastName = lastName             self.mobileNumber = mobileNumber         }     }          struct SignupResponse: Codable {         let token: String     }          static func signup(_ request: SignupRequest) -&gt; APIRequest&lt;SignupResponse&gt; {         return APIRequest(&quot;signup&quot;, payload: request).method(.post)                 .addKnownError(.conflict, &quot;Account already exists&quot;)     } } <\/code><\/pre>\n<p>  \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0432\u0445\u043e\u0434\u0430, \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c <i>SignupRequest<\/i> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 <i>JSONPayload<\/i> (\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c CodyFire \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0438\u043f payload), \u0447\u0442\u043e\u0431\u044b body \u043d\u0430\u0448\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0431\u044b\u043b\u043e \u0432 \u0432\u0438\u0434\u0435 JSON.<\/p>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c payload  <\/p>\n<pre><code>API.auth.signup(request)<\/code><\/pre>\n<p>  \u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u043f\u0435\u0445\u0430 \u0432\u0435\u0440\u043d\u0435\u0442 \u0432\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<p>  \u041f\u043e-\u043c\u043e\u0435\u043c\u0443 \u0443\u0436\u0435 \u043a\u0440\u0443\u0442\u043e, \u0434\u0430?<\/p>\n<h4>\u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 multipart?<\/h4>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u043a\u0438\u0439 <i>Post<\/i>.<\/p>\n<p>  <i>Post+Create.swift<\/i><\/p>\n<pre><code>extension PostController {     struct CreateRequest: MultipartPayload {         var text: String         var tags: [String]         var images: [Attachment]         var video: Data         init (text: String, tags: [String], images: [Attachment], video: Data) {             self.text = text             self.tags = tags             self.images = images             self.video = video         }     }          struct Post: Codable {         let text: String         let tags: [String]         let linksToImages: [String]         let linkToVideo: String     }          static func create(_ request: CreateRequest) -&gt; APIRequest&lt;CreateRequest&gt; {         return APIRequest(&quot;post&quot;, payload: request).method(.post)     } } <\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c multipart \u0444\u043e\u0440\u043c\u0443 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0444\u0430\u0439\u043b\u043e\u0432 \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u0438 \u0441 \u043e\u0434\u043d\u0438\u043c \u0432\u0438\u0434\u0435\u043e.<br \/>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443. \u0422\u0443\u0442 \u0441\u0430\u043c\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0440\u043e <i>Attachment<\/i>.<\/p>\n<pre><code>let videoData = FileManager.default.contents(atPath: &quot;\/path\/to\/video.mp4&quot;)! let imageAttachment = Attachment(data: UIImage(named: &quot;cat&quot;)!.jpeg(.high)!,                                   fileName: &quot;cat.jpg&quot;,                                  mimeType: .jpg) let payload = PostController.CreateRequest(text: &quot;CodyFire is awesome&quot;,                                             tags: [&quot;codyfire&quot;, &quot;awesome&quot;],                                            images: [imageAttachment],                                            video: videoData) API.post.create(payload).onProgress { progress in     print(&quot;\u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0438: \\(progress)&quot;) }.onKnownError { error in     print(error.description) }.onSuccess { createdPost in     print(&quot;\u043f\u043e\u0441\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043d: \\(createdPost)&quot;) } <\/code><\/pre>\n<p>  <i>Attachment<\/i> \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u043c\u0438\u043c\u043e <i>Data<\/i> \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0438 \u0435\u0433\u043e MimeType.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u044c \u0440\u0430\u0437 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u0438 multipart \u0444\u043e\u0440\u043c\u0443 \u0438\u0437 Swift \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Alamofire \u0438\u043b\u0438 \u0433\u043e\u043b\u043e\u0433\u043e <i>URLRequest<\/i> \u044f \u0443\u0432\u0435\u0440\u0435\u043d \u0432\u044b \u043e\u0446\u0435\u043d\u0438\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0443 <i>CodyFire<\/i>.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435, \u043d\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043a\u043b\u0430\u0441\u0441\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b GET \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<p>  <i>Post+Get.swift<\/i><\/p>\n<pre><code>extension PostController {     struct ListQuery: Codable {         let offset, limit: Int         init (offset: Int, limit: Int) {             self.offset = offset             self.limit = limit         }     }          static func get(_ query: ListQuery? = nil) -&gt; APIRequest&lt;[Post]&gt; {         return APIRequest(&quot;post&quot;).query(query)     }          static func get(id: UUID) -&gt; APIRequest&lt;Post&gt; {         return APIRequest(&quot;post\/&quot; + id.uuidString)     } } <\/code><\/pre>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u044d\u0442\u043e<\/p>\n<pre><code>API.post.get(id:)<\/code><\/pre>\n<p>  \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 <i>onSuccess<\/i> \u0432\u0435\u0440\u043d\u0435\u0442 \u0432\u0430\u043c <i>Post<\/i> \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<pre><code>API.post.get(PostController.ListQuery(offset: 0, limit: 100))<\/code><\/pre>\n<p>  \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 <i>ListQuery<\/i> \u043c\u043e\u0434\u0435\u043b\u044c,<br \/>  \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432 \u0438\u0442\u043e\u0433\u0435 APIRequest \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0432 URL-path \u0432\u0438\u0434\u0430<\/p>\n<pre><code>post?limit=0&offset=100<\/code><\/pre>\n<p>  \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u0432 <i>onSuccess<\/i> \u043c\u0430\u0441\u0441\u0438\u0432 <i>[Post]<\/i>.<\/p>\n<p>  \u0412\u044b \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0438 \u043f\u043e-\u0441\u0442\u0430\u0440\u0438\u043d\u043a\u0435 \u043f\u0438\u0441\u0430\u0442\u044c URL-path, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c-\u0442\u043e \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u0442\u0430\u043b\u044c\u043d\u043e Codable&#8217;\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 DELETE<\/p>\n<p>  <i>Post+Delete.swift<\/i><\/p>\n<pre><code>extension PostController {     static func delete(id: UUID) -&gt; APIRequest&lt;Nothing&gt; {         return APIRequest(&quot;post\/&quot; + id.uuidString)               .method(.delete)               .desiredStatusCode(.noContent)     } } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0434\u0432\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>   \u2014 \u0432\u043e\u0437\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f <i>APIRequest, <i>Nothing<\/i> \u2014 \u044d\u0442\u043e \u043f\u0443\u0441\u0442\u0430\u044f <i>Codable<\/i> \u043c\u043e\u0434\u0435\u043b\u044c.<br \/>   \u2014 \u043c\u044b \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043b\u0438, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c 204 NO CONTENT, \u0438 CodyFire \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 <i>onSuccess<\/i>.<\/p>\n<p>  \u041a\u0430\u043a \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 endpoint \u0438\u0437 \u0432\u0430\u0448\u0435\u0433\u043e ViewController&#8217;a \u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u0442\u0435.<\/p>\n<p>  \u041d\u043e \u0442\u0443\u0442 \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430, \u043f\u0435\u0440\u0432\u044b\u0439 \u0441 <i>onSuccess<\/i>, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0435\u0437. \u041d\u0430 \u043d\u0435\u0433\u043e \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c<\/p>\n<pre><code>API.post.delete(id:).execute()<\/code><\/pre>\n<p>  \u0422\u043e \u0435\u0441\u0442\u044c \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435\u0432\u0430\u0436\u043d\u043e \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441, \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0443 \u043d\u0435\u0433\u043e <i>.execute()<\/i> \u0438 \u0432\u0441\u0451, \u0438\u043d\u0430\u0447\u0435 \u043e\u043d \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0438 <i>onSuccess<\/i> \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430.<\/p>\n<h2>\u0414\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h2>\n<p>  <\/p>\n<h4>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/h4>\n<p>  \u0414\u043b\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e API \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a\u0430\u043a\u0438\u043c\u0438-\u043b\u0438\u0431\u043e http-headers \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0445\u044d\u043d\u0434\u043b\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0434\u0430\u0442\u044c \u0433\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0432 <i>AppDelegate<\/i>. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e \u043d\u0430 \u0432\u044b\u0431\u043e\u0440 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 [String: String] \u0438\u043b\u0438 Codable \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f Authorization Bearer.<\/p>\n<p>  1. Codable (\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e)  <\/p>\n<pre><code>CodyFire.shared.fillCodableHeaders = {     struct Headers: Codable {         \/\/NOTE: \u0435\u0441\u043b\u0438 nil, \u0442\u043e \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0432 headers         var Authorization: String?         var anythingElse: String     }     return Headers(Authorization: nil, anythingElse: &quot;hello&quot;) } <\/code><\/pre>\n<p>  2. \u041a\u043b\u0430\u0441\u0441\u0438\u043a\u0430 [String: String]  <\/p>\n<pre><code>CodyFire.shared.fillHeaders = {     guard let apiToken = LocalAuthStorage.savedToken else { return [:] }     return [&quot;Authorization&quot;: &quot;Bearer \\(apiToken)&quot;] } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 http-headers \u0432 \u0437\u0430\u043f\u0440\u043e\u0441<\/h4>\n<p>  \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 APIRequest, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code>APIRequest(&quot;some\/endpoint&quot;).headers([&quot;someKey&quot;: &quot;someValue&quot;])<\/code><\/pre>\n<p>  <\/p>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043d\u0435\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h4>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 <i>AppDelegate<\/i><\/p>\n<pre><code>CodyFire.shared.unauthorizedHandler = {     \/\/\u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 WelcomeScreen } <\/code><\/pre>\n<p>  \u0438\u043b\u0438 \u043c\u0435\u0441\u0442\u043d\u043e \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435<\/p>\n<pre><code>API.post.create(request).onNotAuthorized {     \/\/\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0415\u0441\u043b\u0438 \u0441\u0435\u0442\u044c \u043d\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430<\/h4>\n<p>  <\/p>\n<pre><code>API.post.create(request). onNetworkUnavailable {     \/\/\u043d\u0435\u0442 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u043e\u043c, \u043b\u0438\u0431\u043e \u0430\u0432\u0438\u0430\u0440\u0435\u0436\u0438\u043c, \u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0441\u0435\u0442\u044c\u044e } <\/code><\/pre>\n<p>  \u0438\u043d\u0430\u0447\u0435 \u0432 <i>onError<\/i> \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 -1109 \u0438\u043b\u0438 \u0432 <i>onKnownError<\/i> \u044d\u0442\u043e enum \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <i>._notConnectedToInternet<\/i>  <\/p>\n<blockquote><p>\u041a\u0441\u0442\u0430\u0442\u0438, <i>onKnownError<\/i> \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043f\u0435\u0440\u0435\u0434 <i>onError<\/i>. \u0415\u0441\u043b\u0438 \u0432\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 \u0438 <i>onError<\/i> \u0438 <i>onKnownError<\/i> \u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0442\u043e\u043b\u044c\u043a\u043e <i>onKnownError<\/i>.<\/p><\/blockquote>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a \u0447\u0435\u0433\u043e-\u043b\u0438\u0431\u043e \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u0437\u0430\u043f\u0440\u043e\u0441 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0441\u044f<\/h4>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0434\u0430\u0442\u044c <i>.onRequestStarted<\/i> \u0438 \u043d\u0430\u0447\u0430\u0442\u044c \u0432 \u043d\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043b\u043e\u0430\u0434\u0435\u0440.<br \/>  \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u043e \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430, \u0438 \u0432\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0447\u0435\u043c \u0437\u0440\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043b\u043e\u0430\u0434\u0435\u0440, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<h4>\u041a\u0430\u043a \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c\/\u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043b\u043e\u0433\u043e\u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e<\/h4>\n<p>  <\/p>\n<pre><code>CodyFire.shared.logLevel = .debug CodyFire.shared.logLevel = .error CodyFire.shared.logLevel = .info CodyFire.shared.logLevel = .off <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041a\u0430\u043a \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043b\u043e\u0433\u043e\u0432 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/h4>\n<p>  <\/p>\n<pre><code>.avoidLogError()<\/code><\/pre>\n<p>  <\/p>\n<h4>\u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438 \u043f\u043e-\u0441\u0432\u043e\u0435\u043c\u0443<\/h4>\n<p>  <\/p>\n<pre><code>CodyFire.shared.logHandler = { level, text in     print(&quot;\u041e\u0448\u0438\u0431\u043a\u0430 \u0432 CodyFire: &quot; + text) } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041a\u0430\u043a \u0437\u0430\u0434\u0430\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 http-\u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/h4>\n<p>  \u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u0432\u044b\u0448\u0435, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e CodyFire \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <i>200 OK<\/i> \u0438 \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <i>onSuccess<\/i>.<\/p>\n<p>  \u041d\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e enum, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f <i>201 CREATED<\/i><\/p>\n<pre><code>.desiredStatusCode(.created) <\/code><\/pre>\n<p>  \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u0434<\/p>\n<pre><code>.desiredStatusCode(.custom(777)) <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041e\u0442\u043c\u0435\u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/h4>\n<p>  <\/p>\n<pre><code>.cancel() <\/code><\/pre>\n<p>  \u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0442\u043c\u0435\u043d\u0435\u043d \u043e\u0431\u044a\u044f\u0432\u0438\u0432 <i>.onCancellation<\/i> \u0445\u0435\u043d\u0434\u043b\u0435\u0440<\/p>\n<pre><code>.onCancellation {     \/\/\u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u044b\u043b \u043e\u0442\u043c\u0435\u043d\u0435\u043d } <\/code><\/pre>\n<p>  \u0438\u043d\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d <i>onError<\/i> \u0438\u043b\u0438 \u0432 <i>onKnownError<\/i><\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/h4>\n<p>  <\/p>\n<pre><code>.responseTimeout(30) \/\/\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u0432 30 \u0441\u0435\u043a\u0443\u043d\u0434 <\/code><\/pre>\n<p>  \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0445\u0435\u043d\u0434\u043b\u0435\u0440<\/p>\n<pre><code>. onTimeout {     \/\/\u0437\u0430\u043f\u0440\u043e\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0441\u044f \u043f\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0443 } <\/code><\/pre>\n<p>  \u0438\u043d\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d <i>onError<\/i> \u0438\u043b\u0438 \u0432 <i>onKnownError<\/i>.<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430<\/h4>\n<p>  \u042d\u0442\u043e \u043c\u043e\u044f \u043b\u044e\u0431\u0438\u043c\u0430\u044f \u0444\u0438\u0448\u043a\u0430. \u041e \u043d\u0435\u0439 \u043c\u0435\u043d\u044f \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b \u043e\u0434\u0438\u043d \u0437\u0430\u043a\u0430\u0437\u0447\u0438\u043a \u0438\u0437 \u0421\u0428\u0410, \u0442.\u043a. \u0435\u043c\u0443 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0444\u043e\u0440\u043c\u0430 \u0432\u0445\u043e\u0434\u0430 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u044b\u0441\u0442\u0440\u043e, \u043f\u043e \u0435\u0433\u043e \u043c\u043d\u0435\u043d\u0438\u044e \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u043d\u0435 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e, \u043a\u0430\u043a-\u0431\u0443\u0434\u0442\u043e \u044d\u0442\u043e \u0444\u0435\u0439\u043a, \u0430 \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f.<\/p>\n<p>  \u0418\u0434\u0435\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u0445\u043e\u0442\u0435\u043b, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 email\/password \u0434\u043b\u0438\u043b\u0430\u0441\u044c 2 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435. \u0418 \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0434\u043b\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e 0.5 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0437\u043d\u0430\u0447\u0438\u0442 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043a\u0438\u043d\u0443\u0442\u044c \u0435\u0449\u0435 1.5 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u0432\u0430\u0442\u044c <i>onSuccess<\/i>. \u0410 \u0435\u0441\u043b\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0440\u043e\u0432\u043d\u043e 2 \u0438\u043b\u0438 2.5 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <i>onSuccess<\/i> \u0441\u0440\u0430\u0437\u0443 \u0436\u0435.<\/p>\n<pre><code>.additionalTimeout(2) \/\/\u043c\u0438\u043d\u0438\u043c\u0443\u043c 2 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0421\u0432\u043e\u0439 <i>Date<\/i> encoder\/decoder<\/h4>\n<p>  \u0412 CodyFire \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 <i>DateCodingStrategy<\/i> enum, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0442\u0440\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/p>\n<p>   \u2014 secondsSince1970<br \/>   \u2014 millisecondsSince1970<br \/>   \u2014 formatted(_ customDateFormatter: DateFormatter)<\/p>\n<p>  <i>DateCodingStrategy<\/i> \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0432 \u0442\u0440\u0451\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u0445 \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f decoding \u0438 encoding<br \/>   \u2014 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0432 <i>AppDelegate<\/i><\/p>\n<pre><code>CodyFire.shared.dateEncodingStrategy = .secondsSince1970 let customDateFormatter = DateFormatter() CodyFire.shared.dateDecodingStrategy = .formatted(customDateFormatter) <\/code><\/pre>\n<p>   \u2014 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<pre><code>APIRequest(&quot;some\/endpoint&quot;)     .dateDecodingStrategy(.millisecondsSince1970)     .dateEncodingStrategy(.secondsSince1970) <\/code><\/pre>\n<p>   \u2014 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0430 <i>CustomDateEncodingStrategy<\/i> \u0438\/\u0438\u043b\u0438 <i>CustomDateDecodingStrategy<\/i>.<\/p>\n<pre><code>struct SomePayload: JSONPayload, CustomDateEncodingStrategy, CustomDateDecodingStrategy {    var dateEncodingStrategy: DateCodingStrategy    var dateDecodingStrategy: DateCodingStrategy } <\/code><\/pre>\n<p>  <\/p>\n<h2>\u041a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442<\/h2>\n<p>  <a href=\"https:\/\/github.com\/MihaelIsaev\/CodyFire\">\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043d\u0430 GitHub \u043f\u043e\u0434 MIT \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0435\u0439.<\/a><\/p>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u043e\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 CocoaPods<\/p>\n<pre><code class=\"ruby\">pod 'CodyFire'<\/code><\/pre>\n<p>  \u042f \u043e\u0447\u0435\u043d\u044c \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e CodyFire \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u043c iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c, \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442 \u0434\u043b\u044f \u043d\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043c\u0438\u0440 \u0447\u0443\u0442\u043e\u0447\u043a\u0443 \u043b\u0443\u0447\u0448\u0435, \u0430 \u043b\u044e\u0434\u0435\u0439 \u0434\u043e\u0431\u0440\u0435\u0435.<\/p>\n<p>  \u0412\u043e\u0442 \u0438 \u0432\u0441\u0451, \u0441\u043f\u0430\u0441\u0438\u0431\u043e, \u0447\u0442\u043e \u0443\u0434\u0435\u043b\u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u044f.<\/i><\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <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\/post\/427937\/\"> https:\/\/habr.com\/post\/427937\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>  \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e Swift 4 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b Codable, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c\/\u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438. \u0412 \u043c\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f API \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0438 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0433\u043e\u0434 \u044f \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043b \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043a\u043e\u0434\u0430 \u0432\u043e \u0447\u0442\u043e-\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e\u0435, \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e\u0435 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0443\u0442\u0435\u043c \u0443\u0431\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043a\u043e\u0434\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Codable \u0434\u0430\u0436\u0435 \u0434\u043b\u044f multipart \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 url query \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0422\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0438\u0437 \u0441\u0435\u0431\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043d\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0430\u0441\u044c \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Vapor 3 \u043d\u0430 \u0431\u044d\u043a\u0435\u043d\u0434\u0435. \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430\u0437\u0430\u0434 \u044f \u0432\u044b\u0434\u0435\u043b\u0438\u043b \u0432\u0441\u0435 \u0441\u0432\u043e\u0438 \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438 \u043d\u0430\u0437\u0432\u0430\u043b \u0435\u0435 CodyFire. \u041e \u043d\u0435\u0439 \u043c\u043d\u0435 \u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.  <\/p>\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-291458","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/291458","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=291458"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/291458\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}