{"id":302371,"date":"2020-04-23T15:00:21","date_gmt":"2020-04-23T15:00:21","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=302371"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=302371","title":{"rendered":"CoreData \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437 \u043a\u043e\u0434\u0430. \u0418\u043b\u0438 \u00ab\u041a\u0430\u043a \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 .XCDataModel\u00bb (\u0427\u0430\u0441\u0442\u044c 1)"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/498708\/\">\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f coreData-\u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 XCode, \u0438\u043b\u0438 \u0432\u044b \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043a\u0430\u043a \u044f \u0438 \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0437\u0431\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u043e\u0442 .XCDataModel \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u043e\u0441\u044c \u0447\u0443\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0442\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"kratkaya-predystoriya\">\u041a\u0440\u0430\u0442\u043a\u0430\u044f \u043f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u042f \u0443\u0436\u0435 \u043e\u043a\u043e\u043b\u043e \u043f\u043e\u043b\u0443\u0433\u043e\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u0434 iOS, \u0438 \u0434\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0448\u0451\u043b \u0433\u043b\u0430\u0434\u043a\u043e \u0438 \u0431\u0435\u0437 \u043e\u0441\u043e\u0431\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>  \u041d\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u043e coreData-\u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0430\u0437\u0440\u043e\u0441\u043b\u0430\u0441\u044c \u0434\u043e \u043d\u0435\u043f\u0440\u0438\u043b\u0438\u0447\u043d\u044b\u0445 \u0441 \u043c\u043e\u0435\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432, \u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u043d\u0435\u0437\u0440\u044f\u0447\u0438\u0439, \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u0431\u044a\u0451\u043c\u043e\u043c \u043f\u043e\u043b\u0443\u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043d\u0435 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u044f\u0436\u0435\u043b\u043e, \u043c\u043d\u043e\u0439 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0432\u0441\u0451, \u0447\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f coreData \u0432 \u043a\u043e\u0434.<\/p>\n<p>  <\/p>\n<p>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043f\u043e &quot;\u043d\u0435\u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0439&quot; \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 coreData \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u0430\u043b\u043e, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u043c\u043e\u0438\u0445 \u0432\u044b\u0432\u043e\u0434\u043e\u0432 \u0438 \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u043e\u043a \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0431\u0435\u0437\u0443\u043c\u043d\u044b\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u0445 \u0432 Playground\u0430\u0445 \u0438 \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0431\u0435\u0437\u0443\u043c\u043d\u044b\u0445 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u0445 \u043d\u0430\u0433\u0443\u0433\u043b\u0438\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. <\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0431\u0449\u0435\u043c, \u043f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<p>  <\/p>\n<h2 id=\"nachnyom-s-klassov\">\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h2>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 coreData \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u044b, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 (\u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u043e\u0441\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c, \u0441 \u0447\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c, \u0434\u0430 \u0438 XCode \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043c\u043e\u0433\u0430\u0442\u044c, \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u0438\u043c\u0435\u043d\u0430 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432).<\/p>\n<p>  <\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u0438\u043f\u0438\u0441\u043a\u0430 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, &quot;MO&quot; \u2014 Managed Object. \u042d\u0442\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0443\u0442\u0430\u0442\u044c \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438, \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438, \u043d\u043e \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u043c\u0438\u0441\u044f \u043a coreData.<\/p>\n<p>  <\/p>\n<p>\u0411\u0443\u0434\u0435\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0415\u0441\u0442\u044c \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f (\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u043c CompanyMO);<\/li>\n<li>\u0415\u0441\u0442\u044c \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0438 (\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u043c WorkerMO);<\/li>\n<li>\u041a\u0430\u0436\u0434\u044b\u0439 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 (\u0438\u043b\u0438 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043e\u0432\u0441\u0435);<\/li>\n<li>\u041a\u0430\u0436\u0434\u0430\u044f \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u043d\u0435 \u0438\u043c\u0435\u0442\u044c \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 \u0432\u043e\u0432\u0441\u0435).<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"swift\">@objc(CompanyMO) public class CompanyMO: NSManagedObject { @NSManaged public var companyName: String @NSManaged public var workers: NSSet }  @objc(WorkerMO) public class WorkerMO: NSManagedObject { @NSManaged public var firstname: String @NSManaged public var lastname: String @NSManaged public var company: CompanyMO? }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0441 \u043d\u0435\u0437\u043d\u0430\u043a\u043e\u043c\u044b\u043c\u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.<br \/>  <a href=\"https:\/\/habr.com\/ru\/users\/objc\/\" class=\"user_link\">objc<\/a>() \u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u043e\u043a\u043e\u043b\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u043e \u0441\u043e \u0441\u043a\u043e\u0431\u043a\u0430\u043c\u0438 \u0438 \u0438\u043c\u0435\u043d\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043e\u043d\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0440\u0435\u0434\u043a\u043e.<br \/>  <a href=\"https:\/\/habr.com\/ru\/users\/objc\/\" class=\"user_link\">objc<\/a>(CompanyMO) \u043f\u0435\u0440\u0435\u0434 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0430 CompanyMO \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 CompanyMO \u0432 \u0441\u0440\u0435\u0434\u0435 Objective-C \u0435\u0433\u043e \u0438\u043c\u044f \u0431\u0443\u0434\u0435\u0442 CompanyMO. \u0422\u043e \u0435\u0441\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/users\/objc\/\" class=\"user_link\">objc<\/a>(NameOfClass) \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0438\u043c\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0441\u0440\u0435\u0434\u044b Objective-C.<\/p>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u2014 @NSManaged \u043f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430.<br \/>  @NSManaged \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438 \u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0447\u0438\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u0447\u0442\u043e \u0443\u0436\u0435 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430. \u042f \u043d\u0435 \u0441\u0438\u043b\u0451\u043d \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u044d\u0442\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u043d\u043e \u0437\u043d\u0430\u044e \u0442\u043e\u0447\u043d\u043e (\u0441 \u0441\u0430\u0439\u0442\u0430 Apple, \u043a\u0441\u0442\u0430\u0442\u0438), \u0447\u0442\u043e <em>@NSManaged \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 coreData.<\/em><\/p>\n<p>  <\/p>\n<h2 id=\"podgotovimsya-k-sozdaniyu-modeli\">\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c\u0441\u044f \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438<\/h2>\n<p>  <\/p>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043a\u043e\u0434\u0430 \u2014 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043a\u0440\u0430\u0441\u0438\u0432\u0430\u044f \u0432\u0435\u0449\u044c, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u0443 \u043c\u043e\u0434\u0435\u043b\u044c, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u043e\u0434 \u043f\u0430\u0440\u0443 extension\u043e\u0432 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"swift\">extension NSEntityDescription { convenience init(from classType: AnyClass) { self.init() self.name = NSStringFromClass(classType) self.managedObjectClassName = NSStringFromClass(classType) }  func addProperty(_ property: NSPropertyDescription) { self.properties.append(property) } }  extension NSAttributeDescription { convenience init(name: String, ofType: NSAttributeType, isOptional: Bool = false) { self.init() self.name = name self.attributeType = ofType self.isOptional = isOptional } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0432 \u0432\u044b\u0448\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435.<br \/>  \u041a\u043b\u0430\u0441\u0441 NSEntityDescription \u2014 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 coreData, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c (\u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e, \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430). \u0423 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0435\u0441\u0442\u044c \u0438\u043c\u044f (\u0442\u043e \u0438\u043c\u044f, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0431\u0430\u0437\u0435) \u0438 \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 (managedObjectClassName), \u044d\u0442\u043e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0438\u043c\u044f \u0441\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u0430, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u044c (\u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 \u0432\u044b\u0448\u0435 \u2014 CompanyMO, WorkerMO \u0438 \u0442 \u0434).<br \/>  \u0422\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"swift\">let company = NSEntityDescription() company.name = &quot;CompanyMO&quot; company.managedObjectClassName = &quot;CompanyMO&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0438 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 NSEntityDescription. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"swift\">let company = NSEntityDescription(from: CompanyMO.self) let worker = NSEntityDescription(from: WorkerMO.self)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u043e\u0435\u043c\u0443, \u044d\u0442\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u0435\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"pereydyom-k-opisaniyu-samoy-modeli\">\u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0441\u0430\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/h2>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 (\u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u0432\u0441\u0435, \u043d\u043e \u043e\u0431 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a\u043e\u0434\u0430 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043d\u0438\u0436\u0435), \u0442\u0430\u043a \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<pre><code class=\"swift\">var model: NSManagedObjectModel { let _model = NSManagedObjectModel()  let companyEntity = NSEntityDescription(from: CompanyMO.self) companyEntity.addProperty(NSAttributeDescription(name: &quot;companyName&quot;, ofType: .stringAttributeType)) \/\/ \u0417\u0434\u0435\u0441\u044c \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 CompanyMO.workers, \u043d\u043e \u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044f\u0445 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 let workerEntity = NSEntityDescription(from: WorkerMO.self) workerEntity.addProperty(NSAttributeDescription(name: &quot;firstname&quot;, ofType: .stringAttributeType)) workerEntity.addPropertyNSAttributeDescription((name: &quot;lastname&quot;, ofType: .stringAttributeType))  _model.entities = [companyEntity, workerEntity] return _model }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432\u044b\u0448\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434.<br \/>  \u0423 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 NSManagedObjectModel \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e entities, \u044f\u0432\u043b\u044f\u044e\u0449\u0435\u0435\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 NSEntityDescription.<\/p>\n<p>  <\/p>\n<pre><code class=\"swift\">NSManagedObjectModel.entities: [NSEntityDescription]<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 NSEntityDescription \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0432\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u044d\u0442\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0435 \u0431\u0430\u0437\u0443 \u043a\u0430\u043a\u0438\u043c\u0438-\u043b\u0438\u0431\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0412\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u0447\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0435\u0441\u0442\u044c, \u0438 \u0441 \u043d\u0435\u0439 \u043d\u0430\u0434\u043e \u0443\u043c\u0435\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e NSEntityDescription \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 companyEntity \u0438 workerEntity \u0435\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 companyEntity.properties \u0438 workerEntity.properties, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b NSPropertyDescription.<\/p>\n<p>  <\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 NSPropertyDescription \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c \u0434\u043b\u044f NSAttributeDescription (\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0438\u043b\u0438, \u043f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430) \u0438 NSRelationshipDescription (\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438).<br \/>  \u041f\u0440\u043e NSRelationshipDescription \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 CompanyMO \u0438 WorkerMO;<\/li>\n<li>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u0414\u043b\u044f companyEntity \u044d\u0442\u043e companyName (\u043f\u0440\u043e workers \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438), \u0430 \u0434\u043b\u044f workerEntity \u044d\u0442\u043e firstname \u0438 lastname.<\/li>\n<li>\u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 entities \u0443 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 &quot;\u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u043c\u0438&quot; \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439.<br \/>  \u041e\u0441\u0442\u0430\u043b\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445.<\/p>\n<p>  <\/p>\n<h2 id=\"sozdayom-konteyner\">\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440<\/h2>\n<p>  <\/p>\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043d\u0430 \u0441\u043c\u0435\u043d\u0443 NSPersistentStore \u0438 NSPersistentStoreCoordinator \u043f\u0440\u0438\u0448\u0451\u043b \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 NSPersistentContainer (\u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043d\u0438\u043c \u044f \u0438 \u0443\u043c\u0435\u044e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u0435 \u0437\u0430\u0441\u0442\u0430\u043b \u0442\u0435 \u0443\u0436\u0430\u0441\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0430).<\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 coreData \u0447\u0435\u0440\u0435\u0437 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0435\u043c\u0443 \u043b\u0438\u0448\u044c \u0438\u043c\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<br \/>  \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442 \u0444\u0430\u0439\u043b \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u0442 (\u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442) \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0441 \u043d\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<br \/>  \u041d\u043e \u0443 persistentContainer \u0435\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440.<\/p>\n<p>  <\/p>\n<pre><code class=\"swift\">lazy var persistentContainer: NSPersistentContainer { let _container = NSPersistentContainer(name: &quot;CyrmaxModel&quot;, managedObjectModel: model) _container.loadPersistentStores { (description, error) in \/\/ \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e, \u0434\u0435\u043b\u0430\u0435\u043c \u0447\u0442\u043e-\u0442\u043e } return _container }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0443 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u044f \u0431\u0443\u0434\u0443\u0449\u0435\u0439 (\u0438\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439) \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f persistentContainer \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 coreData \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0434\u043e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043a\u043e\u0434.<\/p>\n<p>  <\/p>\n<h2 id=\"plyusy-opisaniya-modeli-v-kode\">\u041f\u043b\u044e\u0441\u044b \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043a\u043e\u0434\u0435<\/h2>\n<p>  <\/p>\n<ol>\n<li>\u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0430 \u0447\u0442\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u0444\u0430\u0439\u043b\u0430 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0442;<\/li>\n<li>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435 (\u043e\u043f\u044f\u0442\u044c-\u0442\u0430\u043a\u0438 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b);<\/li>\n<li>\u041c\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0445 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u0432 \u0432 \u0441\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u0430\u0445 (\u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0432 \u0441\u0443\u0431\u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0443\u0434\u0430\u043b\u0438\u0432 \u043b\u0438\u0448\u043d\u0438\u0435 &quot;?&quot;, \u043d\u043e \u0432\u0441\u0451 \u0436\u0435).<\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"sokraschaem-kolichestvo-koda\">\u0421\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430<\/h2>\n<p>  <\/p>\n<p>\u0421 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043d\u0430\u043c\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430\u043c\u0438 \u0432\u0441\u0451 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0438\u043c\u043f\u0430\u0442\u0438\u0447\u043d\u043e, \u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0448\u0435\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0434\u0432\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u0430, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0434\u0435\u0441\u044f\u0442\u044c \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435.<br \/>  \u0422\u043e\u0433\u0434\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u043b\u0438\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0441\u0442\u044b\u043d\u044e \u043f\u043e\u0445\u043e\u0436\u0435\u0433\u043e \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u043f\u0430\u043a\u0443\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u044c \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u0432\u0441\u0435 \u0441\u0432\u043e\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f.<br \/>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 WorkerMO, \u0442\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432.<\/p>\n<p>  <\/p>\n<pre><code class=\"swift\">@objc(WorkerMO) public class WorkerMO: NSManagedObject { @NSManaged public var firstname: String @NSManaged public var lastname: String  static private var _entityDescription: NSEntityDescription? static func entityDescription() -&gt; NSEntityDescription { guard self._entityDescription == nil else { return _entityDescription! } let des = NSEntityDescription(from: self) des.addProperty(NSAttributeDescription(name: &quot;firstname&quot;, ofType: .stringAttributeType)) des.addProperty(NSAttributeDescription(name: &quot;lastname&quot;, ofType: .stringAttributeType)) self._entityDescription = des return self._entityDescription! } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0441 CompanyMO (\u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u0432\u044b \u0438 \u0441\u0430\u043c\u0438 \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u0441\u044c).<\/p>\n<p>  <\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u043e\u0440 \u043f\u043e\u043b\u0451\u0442\u043e\u0432.<br \/>  \u0417\u0430\u0447\u0435\u043c \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e _entityDescription \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u043e\u0432\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438?<br \/>  \u041e\u0431 \u044d\u0442\u043e\u043c \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0441 NSRelationshipDescription \u0438 \u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438.<br \/>  \u041d\u043e \u0432 \u043e\u0431\u0449\u0438\u0445 \u0441\u043b\u043e\u0432\u0430\u0445, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0447\u0442\u043e\u0431\u044b CompanyMO.entityDescription() \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0430 <em>\u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 NSEntityDescription<\/em>, \u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0430 \u043d\u043e\u0432\u044b\u0439.<\/p>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 coreData-\u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0437 \u043a\u043e\u0434\u0430 \u2014 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u043d\u044e\u0430\u043d\u0441\u0430\u043c\u0438 \u0438 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u043c\u0438 \u043a\u0430\u043c\u043d\u044f\u043c\u0438. \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u044d\u0442\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u043f\u0440\u043e\u0449\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0430 \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043a\u043e\u0434\u0435 \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0441\u0431\u043e\u0440\u043a\u0443 (\u043d\u0435 \u0442\u0430\u043a \u0441\u0438\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u0438\u0437\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0442 StoryBoard, \u043d\u043e \u0432\u0441\u0451 \u0436\u0435 \u043e\u0449\u0443\u0442\u0438\u043c\u043e), \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0441 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0444\u0430\u0439\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u0434\u0438\u0441\u043a\u0430.<br \/>  \u041d\u0443 \u0430 \u044f \u043f\u043e\u0448\u0451\u043b \u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044f \u043d\u0435\u0437\u0440\u044f\u0447\u0438\u0439, \u0438 \u043c\u043d\u0435 \u0432\u0441\u043b\u0435\u043f\u0443\u044e \u043e\u0447\u0435\u043d\u044c \u0442\u0440\u0443\u0434\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u0441\u043e StoryBoard, \u0442\u0430\u043a \u0438 \u0441 XCDataModel.<\/p>\n<p>  <\/p>\n<h2 id=\"ochen-rekomenduyu-izuchit\">\u041e\u0447\u0435\u043d\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0438\u0437\u0443\u0447\u0438\u0442\u044c<\/h2>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsmanagedobjectmodel\" rel=\"nofollow\">NSManagedObjectModel<\/a>;<\/li>\n<li><a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsentitydescription\" rel=\"nofollow\">NSEntityDescription<\/a>;<\/li>\n<li><a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nspropertydescription\" rel=\"nofollow\">NSPropertyDescription<\/a> \u0438 <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nsattributedescription\" rel=\"nofollow\">NSAttributeDescription<\/a>;<\/li>\n<li>\u041d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u043e <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nspersistentcontainer\" rel=\"nofollow\">NSPersistentContainer<\/a> \u0438 \u0435\u0433\u043e <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nspersistentcontainer\/1640584-init\" rel=\"nofollow\">init(name:managedObjectModel:)<\/a> \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440.<\/li>\n<\/ol>\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\/498708\/\"> https:\/\/habr.com\/ru\/post\/498708\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/498708\/\">\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f coreData-\u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 XCode, \u0438\u043b\u0438 \u0432\u044b \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043a\u0430\u043a \u044f \u0438 \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0437\u0431\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u043e\u0442 .XCDataModel \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u043e\u0441\u044c \u0447\u0443\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0442\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-302371","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/302371","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=302371"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/302371\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=302371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=302371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=302371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}