{"id":322860,"date":"2021-05-10T21:00:26","date_gmt":"2021-05-10T21:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=322860"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=322860","title":{"rendered":"Core Data + Repository pattern. \u0414\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eac\/bbf\/797\/eacbbf797d52cf0d5879b73aee182f48\" width=\"1200\" height=\"588\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u043b\u044e\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e Core Data. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u043a\u0440\u0430\u0442\u043a\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e <a href=\"https:\/\/habr.com\/ru\/post\/436510\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a> \u0438 \u0441\u043a\u043e\u0440\u0435\u0435 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c. \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u0432\u0437\u0433\u043b\u044f\u0434\u043e\u043c \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 IOS \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u0438 \u0432 \u044d\u0442\u043e\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0435 \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u0435\u043b\u0441\u044f \u043f\u043e \u0434\u0443\u0448\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 (\u0434\u0430\u043b\u0435\u0435 &#8212; \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439).  \u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h2>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043a\u0440\u044b\u0442\u044c \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0432\u0435\u0434\u044c, c \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u044d\u0442\u0430 \u0441\u0430\u043c\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f &#8212; \u043d\u0435 \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u0438. \u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c \u043d\u0430\u0434 \u0434\u0430\u043d\u043d\u044b\u043c\u0438: \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c, \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c &#8212; \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f. <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a \u0435\u0433\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438:<\/p>\n<p>&#8212;  \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f. \u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0441\u0435, \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e: \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, UserDefaults, KeyChain, Core Data, Realm, URLCache, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0432 tmp \u0438 \u0442.\u043f.;<\/p>\n<p>&#8212;  \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0437\u043e\u043d \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u043e\u0439 \u043c\u0435\u0436\u0434\u0443 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0442\u0434\u0435\u043b\u044f\u044f \u043e\u0434\u043d\u043e \u043e\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e;<\/p>\n<p>&#8212; \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0435\u0434\u0438\u043d\u043e\u0433\u043e, \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u0432\u0441\u0435 \u044d\u0442\u043e \u0431\u043b\u0430\u0433\u043e\u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f  \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. <\/p>\n<h2>\u0411\u043b\u0438\u0436\u0435 \u043a \u0434\u0435\u0442\u0430\u043b\u044f\u043c<\/h2>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0430\u043c\u044b\u0439 \u043d\u0435\u0431\u043b\u0430\u0433\u043e\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Core Data. <\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 DataProvider (\u0434\u0430\u043b\u0435\u0435 &#8212; DP) &#8212; \u0435\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u043a\u0443\u0434\u0430 &#8212; \u043b\u0438\u0431\u043e (\u0441\u0435\u0442\u044c, UI) \u0438 \u043a\u043b\u0430\u0441\u0442\u044c \u0438\u0445 \u0432  Repository . \u0422\u0430\u043a\u0436\u0435, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, DP \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f, \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u044f \u0434\u043b\u044f \u043d\u0435\u0433\u043e <a href=\"https:\/\/refactoring.guru\/ru\/design-patterns\/facade\" rel=\"noopener noreferrer nofollow\">\u0444\u0430\u0441\u0430\u0434\u043e\u043c<\/a>.  \u041f\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0418\u043c\u0435\u043d\u043d\u043e \u0438\u043c\u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. <\/p>\n<h2>1. Core Data \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 NSManagamentObject<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/147\/bff\/39d\/147bff39d154c46050fb130410fa3d7b.png\" alt=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1\" title=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1\" width=\"1786\" height=\"876\"><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1<\/figcaption><\/figure>\n<p>\u0418\u0434\u0435\u044f \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsmanagedobject\" rel=\"noopener noreferrer nofollow\">NSManagedObject<\/a> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f, \u043d\u043e \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u0443\u0434\u0430\u0447\u043d\u0430\u044f. \u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0432\u0441\u0442\u0430\u044e\u0442 \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c: <\/p>\n<ol>\n<li>\n<p>\u0421ore Data \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0443, \u0432\u0435\u0448\u0430\u044f \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u0440\u0443\u0448\u0430\u044f \u0437\u043e\u043d\u044b \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u0420\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0417\u043d\u0430\u0442\u044c \u043d\u0430 \u0447\u0435\u043c \u0437\u0430\u0432\u044f\u0437\u0430\u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f &#8212; \u0434\u043e\u043b\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439; <\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0435\u0434\u0438\u043d\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 Data Provider, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0445\u0443\u0434\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043d\u0430\u0447\u043d\u0435\u0442 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u0438 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u0439 magic.<\/p>\n<\/li>\n<\/ol>\n<h2>2. Core Data + DB Client<\/h2>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0443\u043c, \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u044d\u0442\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043b\u043e\u0433\u0438\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e DB Client), \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 Repository \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f, \u043a\u0430\u043a \u0432\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043b\u044f\u0436\u0435\u0442 \u0432 DB Client. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0442\u0430\u043a\u043e\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/789\/aa1\/516\/789aa15163aed422a06a6988e7c54000.png\" alt=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 2\" title=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 2\" width=\"1476\" height=\"1002\"><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 2<\/figcaption><\/figure>\n<p>\u041e\u0431\u0435 \u0441\u0445\u0435\u043c\u044b \u0440\u0435\u0448\u0430\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u21161. (Core Data \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f DB Client \u0438 Repository), \u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u21162 \u0438 \u21163 \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u043d\u043e \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0438\u0445 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u0434\u0430\u043b\u044c\u0448\u0435, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0442\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0445\u0435\u043c\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/952\/218\/c1e\/952218c1eae762a320fddf714bd76fe4.png\" alt=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 3\" title=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 3\" width=\"1950\" height=\"970\"><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 3<\/figcaption><\/figure>\n<ol>\n<li>\n<p>Core Data \u043c\u043e\u0436\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u043c. DB Client \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 NSManagedObject \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e; <\/p>\n<\/li>\n<li>\n<p>Repository \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0435\u0434\u0438\u043d\u044b\u0439 \u0438 \u043e\u043d \u043d\u0435 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442\u0441\u044f;<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0438 \u043a\u043e\u043d\u0441\u043e\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0430<\/p>\n<\/li>\n<\/ol>\n<p>\u0417\u0434\u0435\u0441\u044c, \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 &#8212; \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0432\u044b\u0448\u0435-\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0435\u0449\u0435 \u043e\u0434\u043d\u0443, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0432\u0430\u0436\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443: \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043d\u043e\u0432\u044b\u0439 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432 \u043b\u0443\u0447\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u043e\u0434\u0438\u0442\u044c X2 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (DB Client \u0438 Repository). \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430, \u043f\u0440\u043e\u0435\u043a\u0442 \u043b\u0435\u0436\u0438\u0442 <a href=\"https:\/\/github.com\/ArturRuZ\/CoreDataRepositoryPattern\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0442\u0430\u043a\u0438\u043c \u044f \u0432\u0438\u0436\u0443 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439:<\/p>\n<pre><code class=\"swift\">protocol AccessableRepository {    \/\/1    associatedtype DomainModel    \/\/2    var actualSearchedData: Observable&lt;[DomainModel]&gt;? {get}        \/\/3    func save(_ objects: [DomainModel], completion: @escaping ((Result&lt;Void&gt;) -&gt; Void))    \/\/4    func save(_ objects: [DomainModel], clearBeforeSaving: RepositorySearchRequest, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void))        \/\/5    func present(by request: RepositorySearchRequest, completion: @escaping ((Result&lt;[DomainModel]&gt;) -&gt; Void))        \/\/6    func delete(by request: RepositorySearchRequest, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void))    \/\/7    func eraseAllData(completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) }<\/code><\/pre>\n<ol>\n<li>\n<p>\u0414\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0441\u0442\u0430\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsmanagedobjectcontext\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/a>;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0430\u0448 \u043d\u0430\u0431\u043e\u0440 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u043a \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u044e \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f, \u043d\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u044d\u0442\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442.<\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u043c \u0447\u0435\u0440\u0435\u0437 AccessableRepository \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u043e \u0447\u0435\u043c \u0441\u0432\u0438\u0434\u0435\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 4:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/af8\/17f\/8bf\/af817f8bfc254153a186e5da53564341.png\" alt=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 4\" title=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 4\" width=\"1944\" height=\"328\"><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 4<\/figcaption><\/figure>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 Generic-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">class Repository&lt;DomainModel&gt;: NSObject, AccessableRepository {    typealias DomainModel = DomainModel        var actualSearchedData: Observable&lt;[DomainModel]&gt;? {       fatalError(\"actualSearchedData must be overrided\")    }        func save(_ objects: [DomainModel], completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       fatalError(\"save(_ objects: must be overrided\")    }    func save(_ objects: [DomainModel], clearBeforeSaving: RepositorySearchRequest, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       fatalError(\"save(_ objects vs clearBeforeSaving: must be overrided\")    }        func present(by request: RepositorySearchRequest, completion: @escaping ((Result&lt;[DomainModel]&gt;) -&gt; Void)) {       fatalError(\"present(by request: must be overrided\")    }        func delete(by request: RepositorySearchRequest, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       fatalError(\"delete(by request: must be overrided\")    }    func eraseAllData(completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       fatalError(\"eraseAllData(completion: must be overrided\")    } }<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>NSObject \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 NSFetchResultController; <\/p>\n<\/li>\n<li>\n<p>AccessableRepository &#8212; \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u0440\u044f\u0434\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>FatalError \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u043f\u0440\u0435\u0434\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u044f\u043a \u0441\u044e\u0434\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u043e\u0439\u0442\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443:<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f72\/f21\/a3e\/f72f21a3e4ff4c133d7af97ef08f9b82.png\" alt=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 5\" title=\"\u0420\u0438\u0441\u0443\u043d\u043e\u043a 5\" width=\"1914\" height=\"332\"><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 5<\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u044b\u0431\u043e\u0440\u043a\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438:<\/p>\n<pre><code class=\"swift\">protocol RepositorySearchRequest {    \/* NSPredicate = nil,  apply for all records     for deletion sortDescriptor is not Used     *\/    \/\/1    var predicate: NSPredicate? {get}    \/\/2    var sortDescriptors: [NSSortDescriptor] {get} }<\/code><\/pre>\n<ol>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043e\u0442\u0441\u0443\u0441\u0442\u0432\u0443\u0435\u0442 &#8212; \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e \u0432\u0441\u0435\u043c\u0443 \u043d\u0430\u0431\u043e\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 &#8212;  \u043c\u043e\u0436\u0435\u0442 \u043a\u0430\u043a \u043e\u0442\u0441\u0443\u0441\u0442\u0432\u0442\u0432\u043e\u0430\u0442\u044c \u0442\u0430\u043a \u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c. <\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443, \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nspersistentcontainer\" rel=\"noopener noreferrer nofollow\">NSPersistentContainer<\/a> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f),  \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 &#8212; \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0435\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c:<\/p>\n<pre><code class=\"swift\">protocol DBContextProviding {    \/\/1    func mainQueueContext() -&gt; NSManagedObjectContext    \/\/2    func performBackgroundTask(_ block: @escaping (NSManagedObjectContext) -&gt; Void) }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 main Queue, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsfetchedresultscontroller\" rel=\"noopener noreferrer nofollow\">NSFetchedResultsController<\/a>;<\/p>\n<\/li>\n<li>\n<p>\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nspersistentcontainer\/1640581-newbackgroundcontext\" rel=\"noopener noreferrer nofollow\">newBackgroundContext()<\/a>. \u041f\u0440\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u044d\u0442\u0438\u0445 \u0434\u0432\u0443\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/stackoverflow.com\/questions\/53633366\/coredata-whats-the-difference-between-performbackgroundtask-and-newbackgroundc\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0436\u0435, \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u044e (\u043c\u0430\u043f\u0438\u043d\u0433) \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f (NSManagedObject) \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e:<\/p>\n<pre><code class=\"swift\">class DBEntityMapper&lt;DomainModel, Entity&gt; {   \/\/1    func convert(_ entity: Entity) -&gt; DomainModel? {       fatalError(\"convert(_ entity: Entity: must be overrided\")    }   \/\/2    func update(_ entity: Entity, by model: DomainModel) {       fatalError(\"supdate(_ entity: Entity: must be overrided\")    }   \/\/3    func entityAccessorKey(_ entity: Entity) -&gt; String {       fatalError(\"entityAccessorKey must be overrided\")    }   \/\/4    func entityAccessorKey(_ object: DomainModel) -&gt; String {       fatalError(\"entityAccessorKey must be overrided\")    } }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c NSManagedObject \u0432 \u0434\u043e\u043c\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c NSManagedObject \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438;<\/p>\n<\/li>\n<li>\n<p>4. &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 NSManagedObject \u0438 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043e\u0433\u0434\u0430-\u0442\u043e, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 NSManagedObject. \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b\u043e \u0440\u044f\u0434 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0438 \u043e\u0434\u0438\u043d NSManagedObject \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0440\u0443\u0433\u0438\u0445 NSManagedObject. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0437\u043c\u044b\u0432\u0430\u043b \u0437\u043e\u043d\u044b \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u043e \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u043e\u0431\u0449\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. <\/p>\n<p>\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e enum:<\/p>\n<pre><code class=\"swift\">enum DBRepositoryErrors: Error {    case entityTypeError    case noChangesInRepository }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043d\u0446\u0443,  \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0430\u043c\u043e\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 &#8212; \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f.<\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u0414\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f DBContextProvider (\u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432):<\/p>\n<pre><code class=\"swift\">final class DBContextProvider {    \/\/1    private lazy var persistentContainer: NSPersistentContainer = {       let container = NSPersistentContainer(name: \"DataStorageModel\")             container.loadPersistentStores(completionHandler: { (_, error) in          if let error = error as NSError? {             fatalError(\"Unresolved error \\(error),\\(error.userInfo)\")          }          container.viewContext.automaticallyMergesChangesFromParent = true       })       return container    }()    \/\/2    private lazy var mainContext = persistentContainer.viewContext }  \/\/3 \/\/MARK:- DBContextProviding implementation extension DBContextProvider: DBContextProviding {    func performBackgroundTask(_ block: @escaping (NSManagedObjectContext) -&gt; Void) {       persistentContainer.performBackgroundTask(block)    }    func mainQueueContext() -&gt; NSManagedObjectContext {       self.mainContext    } } <\/code><\/pre>\n<ol>\n<li>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f NSPersistentContainer;<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u043d\u044c\u0448\u0435 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u043b \u043e\u0442 \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f DBContextProviding.<\/p>\n<\/li>\n<\/ol>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">final class DBRepository&lt;DomainModel, DBEntity&gt;: Repository&lt;DomainModel&gt;, NSFetchedResultsControllerDelegate {        \/\/1    private let associatedEntityName: String    \/\/2    private let contextSource: DBContextProviding    \/\/3    private var fetchedResultsController: NSFetchedResultsController&lt;NSFetchRequestResult&gt;?    \/\/4    private var searchedData: Observable&lt;[DomainModel]&gt;?    \/\/5    private let entityMapper: DBEntityMapper&lt;DomainModel, DBEntity&gt;        \/\/6    init(contextSource: DBContextProviding, autoUpdateSearchRequest: RepositorySearchRequest?, entityMapper: DBEntityMapper&lt;DomainModel, DBEntity&gt;) {       self.contextSource = contextSource       self.associatedEntityName = String(describing: DBEntity.self)       self.entityMapper = entityMapper              super.init()      \/\/7       guard let request = autoUpdateSearchRequest else { return }       self.searchedData  = .init(value: [])       \/\/self.fetchedResultsController = configureactualSearchedDataUpdating(request)    } }<\/code><\/pre>\n<ol>\n<li>\n<p>C\u0432\u043e\u0439\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsfetchrequest\" rel=\"noopener noreferrer nofollow\">NSFetchRequest<\/a>;<\/p>\n<\/li>\n<li>\n<p>DBContextProviding &#8212; \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f, \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>fetchedResultsController &#8212; \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c, \u043a\u043e\u0433\u0434\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nspersistentstore\" rel=\"noopener noreferrer nofollow\">NSPersistentStore<\/a> (\u043f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0431\u0430\u0437\u0435);<\/p>\n<\/li>\n<li>\n<p>searchedData &#8212; \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 fetchedResultsController \u0438 \u0441\u043b\u0443\u0436\u0438\u0442 \u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439 \u0434\u043b\u044f fetchedResultsController, \u0441\u043a\u0440\u044b\u0432\u0430\u044f \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>entityMapper &#8212;  \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 NSManagedObject \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0438\u0446\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440;<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 autoUpdateSearchReques != nil, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e fetchedResultsController \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044b \u0432 \u0431\u0430\u0437\u0435 ;<\/p>\n<\/li>\n<\/ol>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c, \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"swift\">   private func applyChanges(context: NSManagedObjectContext, mergePolicy: Any = NSMergeByPropertyObjectTrumpMergePolicy, completion: ((Result&lt;Void&gt;) -&gt; Void)? = nil) {       \/\/1       context.mergePolicy = mergePolicy       switch context.hasChanges {       case true:          do {             \/\/2             try context.save()          } catch {             ConsoleLog.logEvent(object: \"DBRepository \\(DBEntity.self)\", method: \"saveIn\", \"Error: \\(error)\")             completion?(Result.error(error))          }          ConsoleLog.logEvent(object: \"DBRepository \\(DBEntity.self)\", method: \"saveIn\", \"Saving Complete\")          completion?(Result(value: ()))       case false:          \/\/3          ConsoleLog.logEvent(object: \"DBRepository \\(DBEntity.self)\", method: \"saveIn\", \"No changes in context\")          completion?(Result(error: DBRepositoryErrors.noChangesInRepository))       }    }<\/code><\/pre>\n<ol>\n<li>\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsmergepolicy\" rel=\"noopener noreferrer nofollow\">mergePolicy<\/a> &#8212; \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0442\u043e, \u043a\u0430\u043a \u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u044b \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u0434\u0430\u0435\u0442 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u043d\u0435 \u0432 persistent store;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 persistent store;<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442, \u0432 completion-\u0431\u043b\u043e\u043a \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">   private func saveIn(data: [DomainModel], clearBeforeSaving: RepositorySearchRequest?, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void))  {       contextSource.performBackgroundTask() { context in                    \/\/1          if let clearBeforeSaving = clearBeforeSaving {             let clearFetchRequest = NSFetchRequest&lt;NSManagedObject&gt;(entityName: self.associatedEntityName)             clearFetchRequest.predicate = clearBeforeSaving.predicate             clearFetchRequest.includesPropertyValues = false             (try? context.fetch(clearFetchRequest))?.forEach({ context.delete($0) })          }                    \/\/2          var existingObjects: [String: DBEntity] = [:]          let fetchRequest = NSFetchRequest&lt;NSManagedObject&gt;(entityName: self.associatedEntityName)                    (try? context.fetch(fetchRequest) as? [DBEntity])?.forEach({             let accessor = self.entityMapper.entityAccessorKey($0)             existingObjects[accessor] = $0          })                    data.forEach({             let accessor = self.entityMapper.entityAccessorKey($0)             \/\/3             let entityForUpdate: DBEntity? = existingObjects[accessor] ??  NSEntityDescription.insertNewObject(forEntityName: self.associatedEntityName, into: context) as? DBEntity             \/\/4             guard let entity = entityForUpdate else { return }             self.entityMapper.update(entity, by: $0)          })          \/\/5          self.applyChanges(context: context, completion: completion)       }    }<\/code><\/pre>\n<ol>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043f\u0435\u0440\u0435\u0434 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u044b\u0445 (\u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430);<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0434\u043b\u044f \u0438\u0445 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c entityAccessorKey \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 NSManagedObject;<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u0430\u043f\u0438\u043d\u0433\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438\u0437 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 NSManagedObject;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. <\/p>\n<\/li>\n<\/ol>\n<p><strong><em>\u0412\u0430\u0436\u043d\u043e:  <\/em><\/strong><em>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u0430\u0441 \u0441\u043c\u0443\u0442\u0438\u043b \u043f.2.,  \u0434\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.  \u042f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b \u0437\u0430\u043c\u0435\u0440\u044b (ExampleCase3 \u0432 \u0434\u0435\u043c\u043e-\u043f\u0440\u043e\u0435\u043a\u0442\u0435) \u043d\u0430 10 000 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, iPhone 6s Plus IOS 12.4.1 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b: <\/em><\/p>\n<ul>\n<li>\n<p><em>\u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0438\u0441\u0438\/\u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 0,9 \u0434\u043e 1.8 \u0441\u0435\u043a, c\u043a\u0430\u0447\u043e\u043a \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043f\u0438\u043a\u0435 \u0434\u043e 33 \u043c\u0431; <\/em><\/p>\n<\/li>\n<li>\n<p><em>\u0435\u0441\u043b\u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u043f2 \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u043d\u043e\u0432\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0438\u0441\u0438\/\u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 +- 20 \u0441\u0435\u043a, c\u043a\u0430\u0447\u043e\u043a \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043f\u0438\u043a\u0435 \u0434\u043e 50 \u043c\u0431. <\/em><\/p>\n<\/li>\n<\/ul>\n<p><em>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f \u0431\u044b \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043b \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0438\u0445 \u043d\u0430 \u0447\u0430\u0441\u0442\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/em><a href=\"https:\/\/developer.apple.com\/library\/archive\/featuredarticles\/CoreData_Batch_Guide\/BatchUpdates\/BatchUpdates.html\" rel=\"noopener noreferrer nofollow\"><em> batchUpdate \u0438 batchDelete,<\/em><\/a><em> \u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 IOS 13 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f <\/em><a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsbatchinsertrequest\" rel=\"noopener noreferrer nofollow\"><em>batchInsert<\/em><\/a><em>. <\/em><\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <strong><em>save<\/em><\/strong> c\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0432\u044b\u0437\u043e\u0432\u0443 \u043c\u0435\u0442\u043e\u0434\u0430 <strong><em>saveIn<\/em><\/strong>:<\/p>\n<pre><code class=\"swift\">  override func save(_ objects: [DomainModel], completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       saveIn(data: objects, clearBeforeSaving: nil, completion: completion)    }    override func save(_ objects: [DomainModel], clearBeforeSaving: RepositorySearchRequest, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       saveIn(data: objects, clearBeforeSaving: clearBeforeSaving, completion: completion)    }<\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b <strong><em>present, delete<\/em><\/strong>, <strong><em>eraseAllData<\/em><\/strong>  \u0437\u0430\u0432\u044f\u0437\u0430\u043d\u044b \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441  NSFetchRequest. \u0412 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0432\u0438\u0436\u0443 \u0441\u043c\u044b\u0441\u043b\u0430 \u0437\u0430\u043e\u0441\u0442\u0440\u044f\u0442\u044c \u043d\u0430 \u043d\u0438\u0445 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"swift\"> override func present(by request: RepositorySearchRequest, completion: @escaping ((Result&lt;[DomainModel]&gt;) -&gt; Void)) {       \/\/1       let fetchRequest = NSFetchRequest&lt;NSManagedObject&gt;(entityName: associatedEntityName)       fetchRequest.predicate = request.predicate       fetchRequest.sortDescriptors = request.sortDescriptors       contextSource.performBackgroundTask() { context in          do {             \/\/2             let rawData = try context.fetch(fetchRequest)             guard rawData.isEmpty == false else {return completion(Result(value: [])) }             guard let results = rawData as? [DBEntity] else {                completion(Result(value: []))                assertionFailure(DBRepositoryErrors.entityTypeError.localizedDescription)                return             }             \/\/3             let converted = results.compactMap({ return self.entityMapper.convert($0) })             completion(Result(value: converted))          } catch {             completion(Result(error: error))          }       }    }        override func delete(by request: RepositorySearchRequest, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       \/\/1       let fetchRequest = NSFetchRequest&lt;NSManagedObject&gt;(entityName: associatedEntityName)       fetchRequest.predicate = request.predicate       fetchRequest.includesPropertyValues = false       contextSource.performBackgroundTask() { context in          \/\/2          let results = try? context.fetch(fetchRequest)          results?.forEach({ context.delete($0) })          \/\/3          self.applyChanges(context: context, completion: completion)       }    }    override func eraseAllData(completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       \/\/1       let fetchRequest = NSFetchRequest&lt;NSFetchRequestResult&gt;(entityName: associatedEntityName)       let batchDeleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)              batchDeleteRequest.resultType = .resultTypeObjectIDs       contextSource.performBackgroundTask({ context in          do {             \/\/2             let result = try context.execute(batchDeleteRequest)             guard let deleteResult = result as? NSBatchDeleteResult,                   let ids = deleteResult.result as? [NSManagedObjectID]             else {                completion(Result.error(DBRepositoryErrors.noChangesInRepository))                return             }                          let changes = [NSDeletedObjectsKey: ids]             NSManagedObjectContext.mergeChanges(                fromRemoteContextSave: changes,                into: [self.contextSource.mainQueueContext()]             )             \/\/3             completion(Result(value: ()))             return          } catch {             ConsoleLog.logEvent(object: \"DBRepository \\(DBEntity.self)\", method: \"eraseAllData\", \"Error: \\(error)\")             completion(Result.error(error))          }       })<\/code><\/pre>\n<ol>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u043e\u0440\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0432\u0437\u0440\u0430\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f FetchedResultsController.  \u0414\u043b\u044f \u0435\u0433\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"swift\"> private func configureactualSearchedDataUpdating(_ request: RepositorySearchRequest) -&gt; NSFetchedResultsController&lt;NSFetchRequestResult&gt; {       \/\/1       let fetchRequest: NSFetchRequest&lt;NSFetchRequestResult&gt; = NSFetchRequest(entityName: associatedEntityName)              fetchRequest.predicate = request.predicate       fetchRequest.sortDescriptors = request.sortDescriptors              \/\/2       let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest,                                                                 managedObjectContext: contextSource.mainQueueContext(), sectionNameKeyPath: nil,                                                                 cacheName: nil)       \/\/3       fetchedResultsController.delegate = self       try? fetchedResultsController.performFetch()       if let content = fetchedResultsController.fetchedObjects as? [DBEntity] {          updateObservableContent(content)       }       return fetchedResultsController    }   func updateObservableContent(_ content: [DBEntity]) {       let converted = content.compactMap({ return self.entityMapper.convert($0) })    \/\/4       searchedData?.value = converted    }<\/code><\/pre>\n<ol>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 NSFetchedResultsController;<\/p>\n<\/li>\n<li>\n<p>performFetch() \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0435 \u0434\u043e\u0436\u0438\u0434\u0430\u044f\u0441\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0431\u0430\u0437\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Ofline First;<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 searchedData,  \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0435\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 (\u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u044e\u0442\u0441\u044f) \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438. <\/p>\n<\/li>\n<\/ol>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043d\u0446\u0443.  \u0414\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0441\u0442\u0430\u043b\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0441 Core Data \u0441\u0442\u0430\u043b\u0430 \u0432\u0435\u0437\u0434\u0435 \u0435\u0434\u0438\u043d\u0430\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e EntityMapper (\u043d\u043e\u0432\u043e\u0435 Entity \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435). \u0412\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e \u043c\u0430\u043f\u0438\u043d\u0433\u0443 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0431\u0440\u0430\u043d\u0430 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435; <\/p>\n<\/li>\n<li>\n<p>Data \u0441\u043b\u043e\u0439 \u0441\u0442\u0430\u043b \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u0447\u043d\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 100500 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432, \u0438\u043b\u0438 \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438.  <\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043e\u0439\u0442\u0438 \u043d\u0435 \u0432\u0441\u0435\u043c, \u0438 \u044d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0435\u0433\u043e \u043c\u0438\u043d\u0443\u0441. \u0427\u0430\u0441\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0432 \u0442.\u0447 \u0438 \u043e\u0442 \u0431\u044d\u043a-\u044d\u043d\u0434\u0430.  \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 &#8212; \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u043e\u0432 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Core Data. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0434\u0435\u043c\u043e-\u043f\u0440\u043e\u0435\u043a\u0442, \u0434\u043e\u043f\u0438\u043b\u0438\u0432\u0430\u0439\u0442\u0435 \u0435\u0433\u043e \u043f\u043e\u0434 \u0441\u0435\u0431\u044f, \u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c!  <\/p>\n<p><strong><em>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u041b\u0435\u0433\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0438\u043d\u0433\u0430, \u043f\u043e\u043c\u0435\u043d\u044c\u0448\u0435 \u0431\u0430\u0433\u043e\u0432, \u043f\u043e\u0431\u043e\u043b\u044c\u0448\u0435 \u0444\u0438\u0447!<\/em><\/strong><\/p>\n<\/div>\n<p> \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\/post\/542752\/\"> https:\/\/habr.com\/ru\/post\/542752\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u043b\u044e\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e Core Data. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u043a\u0440\u0430\u0442\u043a\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e <a href=\"https:\/\/habr.com\/ru\/post\/436510\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a> \u0438 \u0441\u043a\u043e\u0440\u0435\u0435 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c. \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u0432\u0437\u0433\u043b\u044f\u0434\u043e\u043c \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 IOS \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u0438 \u0432 \u044d\u0442\u043e\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0435 \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u0435\u043b\u0441\u044f \u043f\u043e \u0434\u0443\u0448\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 (\u0434\u0430\u043b\u0435\u0435 &#8212; \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439).  \u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h2>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043a\u0440\u044b\u0442\u044c \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0432\u0435\u0434\u044c, c \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u044d\u0442\u0430 \u0441\u0430\u043c\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f &#8212; \u043d\u0435 \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u0438. \u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c \u043d\u0430\u0434 \u0434\u0430\u043d\u043d\u044b\u043c\u0438: \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c, \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c &#8212; \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f. <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a \u0435\u0433\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438:<\/p>\n<p>&#8212;  \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f. \u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0441\u0435, \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e: \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, UserDefaults, KeyChain, Core Data, Realm, URLCache, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0432 tmp \u0438 \u0442.\u043f.;<\/p>\n<p>&#8212;  \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0437\u043e\u043d \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u043e\u0439 \u043c\u0435\u0436\u0434\u0443 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0442\u0434\u0435\u043b\u044f\u044f \u043e\u0434\u043d\u043e \u043e\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e;<\/p>\n<p>&#8212; \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0435\u0434\u0438\u043d\u043e\u0433\u043e, \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u0432\u0441\u0435 \u044d\u0442\u043e \u0431\u043b\u0430\u0433\u043e\u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f  \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. <\/p>\n<h2>\u0411\u043b\u0438\u0436\u0435 \u043a \u0434\u0435\u0442\u0430\u043b\u044f\u043c<\/h2>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0430\u043c\u044b\u0439 \u043d\u0435\u0431\u043b\u0430\u0433\u043e\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Core Data. <\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 DataProvider (\u0434\u0430\u043b\u0435\u0435 &#8212; DP) &#8212; \u0435\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u043a\u0443\u0434\u0430 &#8212; \u043b\u0438\u0431\u043e (\u0441\u0435\u0442\u044c, UI) \u0438 \u043a\u043b\u0430\u0441\u0442\u044c \u0438\u0445 \u0432  Repository . \u0422\u0430\u043a\u0436\u0435, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, DP \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f, \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u044f \u0434\u043b\u044f \u043d\u0435\u0433\u043e <a href=\"https:\/\/refactoring.guru\/ru\/design-patterns\/facade\" rel=\"noopener noreferrer nofollow\">\u0444\u0430\u0441\u0430\u0434\u043e\u043c<\/a>.  \u041f\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0418\u043c\u0435\u043d\u043d\u043e \u0438\u043c\u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. <\/p>\n<h2>1. Core Data \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 NSManagamentObject<\/h2>\n<figure class=\"full-width\"><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1<\/figcaption><\/figure>\n<p>\u0418\u0434\u0435\u044f \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsmanagedobject\" rel=\"noopener noreferrer nofollow\">NSManagedObject<\/a> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f, \u043d\u043e \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u0443\u0434\u0430\u0447\u043d\u0430\u044f. \u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0432\u0441\u0442\u0430\u044e\u0442 \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c: <\/p>\n<ol>\n<li>\n<p>\u0421ore Data \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0443, \u0432\u0435\u0448\u0430\u044f \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u0440\u0443\u0448\u0430\u044f \u0437\u043e\u043d\u044b \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u0420\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0417\u043d\u0430\u0442\u044c \u043d\u0430 \u0447\u0435\u043c \u0437\u0430\u0432\u044f\u0437\u0430\u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f &#8212; \u0434\u043e\u043b\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439; <\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0435\u0434\u0438\u043d\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 Data Provider, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0445\u0443\u0434\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043d\u0430\u0447\u043d\u0435\u0442 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u0438 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u0439 magic.<\/p>\n<\/li>\n<\/ol>\n<h2>2. Core Data + DB Client<\/h2>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0443\u043c, \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u044d\u0442\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043b\u043e\u0433\u0438\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e DB Client), \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 Repository \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f, \u043a\u0430\u043a \u0432\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043b\u044f\u0436\u0435\u0442 \u0432 DB Client. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0442\u0430\u043a\u043e\u0435:<\/p>\n<figure class=\"full-width\"><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 2<\/figcaption><\/figure>\n<p>\u041e\u0431\u0435 \u0441\u0445\u0435\u043c\u044b \u0440\u0435\u0448\u0430\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u21161. (Core Data \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f DB Client \u0438 Repository), \u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u21162 \u0438 \u21163 \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u043d\u043e \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0438\u0445 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u0434\u0430\u043b\u044c\u0448\u0435, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0442\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0445\u0435\u043c\u0435:<\/p>\n<figure class=\"full-width\"><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 3<\/figcaption><\/figure>\n<ol>\n<li>\n<p>Core Data \u043c\u043e\u0436\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u043c. DB Client \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 NSManagedObject \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e; <\/p>\n<\/li>\n<li>\n<p>Repository \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0435\u0434\u0438\u043d\u044b\u0439 \u0438 \u043e\u043d \u043d\u0435 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442\u0441\u044f;<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0438 \u043a\u043e\u043d\u0441\u043e\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0430<\/p>\n<\/li>\n<\/ol>\n<p>\u0417\u0434\u0435\u0441\u044c, \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 &#8212; \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0432\u044b\u0448\u0435-\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0435\u0449\u0435 \u043e\u0434\u043d\u0443, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0432\u0430\u0436\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443: \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043d\u043e\u0432\u044b\u0439 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432 \u043b\u0443\u0447\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u043e\u0434\u0438\u0442\u044c X2 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (DB Client \u0438 Repository). \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430, \u043f\u0440\u043e\u0435\u043a\u0442 \u043b\u0435\u0436\u0438\u0442 <a href=\"https:\/\/github.com\/ArturRuZ\/CoreDataRepositoryPattern\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0442\u0430\u043a\u0438\u043c \u044f \u0432\u0438\u0436\u0443 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439:<\/p>\n<pre><code class=\"swift\">protocol AccessableRepository {    \/\/1    associatedtype DomainModel    \/\/2    var actualSearchedData: Observable&lt;[DomainModel]&gt;? {get}        \/\/3    func save(_ objects: [DomainModel], completion: @escaping ((Result&lt;Void&gt;) -&gt; Void))    \/\/4    func save(_ objects: [DomainModel], clearBeforeSaving: RepositorySearchRequest, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void))        \/\/5    func present(by request: RepositorySearchRequest, completion: @escaping ((Result&lt;[DomainModel]&gt;) -&gt; Void))        \/\/6    func delete(by request: RepositorySearchRequest, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void))    \/\/7    func eraseAllData(completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) }<\/code><\/pre>\n<ol>\n<li>\n<p>\u0414\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0441\u0442\u0430\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsmanagedobjectcontext\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/a>;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0430\u0448 \u043d\u0430\u0431\u043e\u0440 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u043a \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u044e \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f, \u043d\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u044d\u0442\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442.<\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u043c \u0447\u0435\u0440\u0435\u0437 AccessableRepository \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u043e \u0447\u0435\u043c \u0441\u0432\u0438\u0434\u0435\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 4:<\/p>\n<figure class=\"full-width\"><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 4<\/figcaption><\/figure>\n<p>\u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 Generic-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">class Repository&lt;DomainModel&gt;: NSObject, AccessableRepository {    typealias DomainModel = DomainModel        var actualSearchedData: Observable&lt;[DomainModel]&gt;? {       fatalError(\"actualSearchedData must be overrided\")    }        func save(_ objects: [DomainModel], completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       fatalError(\"save(_ objects: must be overrided\")    }    func save(_ objects: [DomainModel], clearBeforeSaving: RepositorySearchRequest, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       fatalError(\"save(_ objects vs clearBeforeSaving: must be overrided\")    }        func present(by request: RepositorySearchRequest, completion: @escaping ((Result&lt;[DomainModel]&gt;) -&gt; Void)) {       fatalError(\"present(by request: must be overrided\")    }        func delete(by request: RepositorySearchRequest, completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       fatalError(\"delete(by request: must be overrided\")    }    func eraseAllData(completion: @escaping ((Result&lt;Void&gt;) -&gt; Void)) {       fatalError(\"eraseAllData(completion: must be overrided\")    } }<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>NSObject \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 NSFetchResultController; <\/p>\n<\/li>\n<li>\n<p>AccessableRepository &#8212; \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u0440\u044f\u0434\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>FatalError \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u043f\u0440\u0435\u0434\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u044f\u043a \u0441\u044e\u0434\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u043e\u0439\u0442\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443:<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><figcaption>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 5<\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u044b\u0431\u043e\u0440\u043a\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438:<\/p>\n<pre><code class=\"swift\">protocol RepositorySearchRequest {    \/* NSPredicate = nil,  apply for all records     for deletion sortDescriptor is not Used     *\/    \/\/1    var predicate: NSPredicate? {get}    \/\/2    var sortDescriptors: [NSSortDescriptor] {get} }<\/code><\/pre>\n<ol>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u0435\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043e\u0442\u0441\u0443\u0441\u0442\u0432\u0443\u0435\u0442 &#8212; \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e \u0432\u0441\u0435\u043c\u0443 \u043d\u0430\u0431\u043e\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 &#8212;  \u043c\u043e\u0436\u0435\u0442 \u043a\u0430\u043a \u043e\u0442\u0441\u0443\u0441\u0442\u0432\u0442\u0432\u043e\u0430\u0442\u044c \u0442\u0430\u043a \u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c. <\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443, \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nspersistentcontainer\" rel=\"noopener noreferrer nofollow\">NSPersistentContainer<\/a> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f),  \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 &#8212; \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0435\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c:<\/p>\n<pre><code class=\"swift\">protocol DBContextProviding {    \/\/1    func mainQueueContext() -&gt; NSManagedObjectContext    \/\/2    func performBackgroundTask(_ block: @escaping (NSManagedObjectContext) -&gt; Void) }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 main Queue, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsfetchedresultscontroller\" rel=\"noopener noreferrer nofollow\">NSFetchedResultsController<\/a>;<\/p>\n<\/li>\n<li>\n<p>\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nspersistentcontainer\/1640581-newbackgroundcontext\" rel=\"noopener noreferrer nofollow\">newBackgroundContext()<\/a>. \u041f\u0440\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u044d\u0442\u0438\u0445 \u0434\u0432\u0443\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/stackoverflow.com\/questions\/53633366\/coredata-whats-the-difference-between-performbackgroundtask-and-newbackgroundc\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u0436\u0435, \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u044e (\u043c\u0430\u043f\u0438\u043d\u0433) \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f (NSManagedObject) \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e:<\/p>\n<pre><code class=\"swift\">class DBEntityMapper&lt;DomainModel, Entity&gt; {   \/\/1    func convert(_ entity: Entity) -&gt; DomainModel? {       fatalError(\"convert(_ entity: Entity: must be overrided\")    }   \/\/2    func update(_ entity: Entity, by model: DomainModel) {       fatalError(\"supdate(_ entity: Entity: must be overrided\")    }   \/\/3    func entityAccessorKey(_ entity: Entity) -&gt; String {       fatalError(\"entityAccessorKey must be overrided\")    }   \/\/4    func entityAccessorKey(_ object: DomainModel) -&gt; String {       fatalError(\"entityAccessorKey must be overrided\")    } }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c NSManagedObject \u0432 \u0434\u043e\u043c\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c NSManagedObject \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438;<\/p>\n<\/li>\n<li>\n<p>4. &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 NSManagedObject \u0438 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043e\u0433\u0434\u0430-\u0442\u043e, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 NSManagedObject. \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b\u043e \u0440\u044f\u0434 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0438 \u043e\u0434\u0438\u043d NSManagedObject \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0440\u0443\u0433\u0438\u0445 NSManagedObject. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0437\u043c\u044b\u0432\u0430\u043b \u0437\u043e\u043d\u044b \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u043e \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u043e\u0431\u0449\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. <\/p>\n<p>\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e enum:<\/p>\n<pre><code class=\"swift\">enum DBRepositoryErrors: Error {    case entityTypeError    case noChangesInRepository }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043d\u0446\u0443,  \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0430\u043c\u043e\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 &#8212; \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f.<\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u0414\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f DBContextProvider (\u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432):<\/p>\n<pre><code class=\"swift\">final class DBContextProvider {    \/\/1    private lazy var persistentContainer: NSPersistentContainer = {       let container = NSPersistentContainer(name: \"DataStorageModel\")             container.loadPersistentStores(completionHandler: { (_, error) in          if let error = error as NSError? {             fatalError(\"Unresolved error \\(error),\\(error.userInfo)\")          }          container.viewContext.automaticallyMergesChangesFromParent = true       })       return container    }()    \/\/2    private lazy var mainContext = persistentContainer.viewContext }  \/\/3 \/\/MARK:- DBContextProviding implementation extension DBContextProvider: DBContextProviding {  <\/code><\/pre>\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-322860","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/322860","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=322860"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/322860\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=322860"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=322860"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=322860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}