@@ -45,21 +45,21 @@ The example projects are a good starting point
4545We create our ` Note ` entity programmatically:
4646``` swift
4747@objc (Note )
48- public class Note : NSManagedObject , Identifiable {
49- @nonobjc public class func fetchRequest () -> NSFetchRequest<Note> {
48+ final class Note : NSManagedObject , Identifiable {
49+ @nonobjc class func fetchRequest () -> NSFetchRequest<Note> {
5050 return NSFetchRequest< Note> (entityName : " Note" )
5151 }
5252
53- @NSManaged public var id: UUID
54- @NSManaged public var text: String
55- @NSManaged public var created: Date
53+ @NSManaged var id: UUID
54+ @NSManaged var text: String
55+ @NSManaged var created: Date
5656}
5757```
5858
5959Extending ` Note ` to conform to ` SelfDescribingCoreDataEntity ` will give us a declarative representation of ` Note ` 's entity description:
6060``` swift
6161extension Note : SelfDescribingCoreDataEntity {
62- public static var entityDescription = Note.description (
62+ static var entityDescription = Note.description (
6363 .uuid (\.id ),
6464 .string (\.text ),
6565 .date (\.created )
@@ -80,46 +80,46 @@ let container = try await NSManagedObjectModel(
8080We create an ` Author ` entity programmatically. Note the ` addToBooks ` and ` removeFromBooks ` function signatures. We are exposing objective-c methods that get generated for us to add to our ` _books ` ordered set:
8181``` swift
8282@objc (Author )
83- final public class Author : NSManagedObject , Identifiable {
84- @nonobjc public class func fetchRequest () -> NSFetchRequest<Author> {
83+ final class Author : NSManagedObject , Identifiable {
84+ @nonobjc class func fetchRequest () -> NSFetchRequest<Author> {
8585 return NSFetchRequest< Author> (entityName : " Author" )
8686 }
8787
88- @NSManaged public var id: UUID
89- @NSManaged public var name: String
90- @NSManaged public var _books: NSOrderedSet
88+ @NSManaged var id: UUID
89+ @NSManaged var name: String
90+ @NSManaged var _books: NSOrderedSet
9191
92- public var books: Array <Book> {
92+ var books: Array <Book> {
9393 get { _books.array as! Array < Book> }
9494 }
9595
9696 @objc (add_booksObject: )
97- @NSManaged public func addToBooks (_ value : Book)
97+ @NSManaged func addToBooks (_ value : Book)
9898
9999 @objc (remove_booksObject: )
100- @NSManaged public func removeFromBooks (_ value : Book)
100+ @NSManaged func removeFromBooks (_ value : Book)
101101
102102 @objc (add_books: )
103- @NSManaged public func addToBooks (_ values : Set <Book>)
103+ @NSManaged func addToBooks (_ values : Set <Book>)
104104
105105 @objc (remove_books: )
106- @NSManaged public func removeFromBooks (_ values : Set <Book>)
106+ @NSManaged func removeFromBooks (_ values : Set <Book>)
107107}
108108```
109109
110110We create a ` Book ` entity programmatically. Note that it should be impossible to create a book without adding the book to it's authors ` books ` property, since we have an inverse relationship. We achieve this by creating an initializer that adds the book to it's ` Author ` and marking all other initializers as ` unavailable ` :
111111``` swift
112112@objc (Book )
113- final public class Book : NSManagedObject , Identifiable {
114- @nonobjc public class func fetchRequest () -> NSFetchRequest<Book> {
113+ final class Book : NSManagedObject , Identifiable {
114+ @nonobjc class func fetchRequest () -> NSFetchRequest<Book> {
115115 return NSFetchRequest< Book> (entityName : " Book" )
116116 }
117117
118- @NSManaged public var id: UUID
119- @NSManaged public var title: String
120- @NSManaged public var author: Author
118+ @NSManaged var id: UUID
119+ @NSManaged var title: String
120+ @NSManaged var author: Author
121121
122- public init (
122+ init (
123123 context : NSManagedObjectContext,
124124 id : UUID,
125125 title : String ,
@@ -133,17 +133,17 @@ final public class Book: NSManagedObject, Identifiable {
133133 }
134134
135135 @available (* , unavailable )
136- public override init (entity : NSEntityDescription, insertInto context : NSManagedObjectContext? ) {
136+ override init (entity : NSEntityDescription, insertInto context : NSManagedObjectContext? ) {
137137 super .init (entity : entity, insertInto : context)
138138 }
139139
140140 @available (* , unavailable )
141- public init (context : NSManagedObjectContext) {
141+ init (context : NSManagedObjectContext) {
142142 fatalError ()
143143 }
144144
145145 @available (* , unavailable )
146- public init () {
146+ init () {
147147 fatalError ()
148148 }
149149}
@@ -152,7 +152,7 @@ final public class Book: NSManagedObject, Identifiable {
152152Extending ` Author ` to conform to ` SelfDescribingCoreDataEntity ` will give us a declarative representation of ` Author ` 's entity description. We also set up the to-many relationship to the ` Book ` entity:
153153``` swift
154154extension Author : SelfDescribingCoreDataEntity {
155- public static var entityDescription = Author.description (
155+ static var entityDescription = Author.description (
156156 .uuid (\.id ),
157157 .string (\.name ),
158158 .relationship (\._books , .init (
@@ -167,7 +167,7 @@ extension Author: SelfDescribingCoreDataEntity {
167167Extending ` Book ` to conform to ` SelfDescribingCoreDataEntity ` will give us a declarative representation of ` Book ` 's entity description. We also set up the to-one relationship to the ` Book ` 's ` Author ` entity:
168168``` swift
169169extension Book : SelfDescribingCoreDataEntity {
170- public static var entityDescription = Book.description (
170+ static var entityDescription = Book.description (
171171 .uuid (\.id ),
172172 .string (\.title ),
173173 .relationship (\.author , .init (
@@ -192,9 +192,9 @@ If we didn't care about the order of books on our `Author` entity we would decla
192192
193193``` Swift
194194@objc (Author )
195- final public class Author : NSManagedObject , Identifiable {
195+ final class Author : NSManagedObject , Identifiable {
196196 // ...
197- @NSManaged public var _books: NSSet
197+ @NSManaged var _books: NSSet
198198
199199 var books: Set <Book> {
200200 get { _books as! Set < Book> }
@@ -205,7 +205,7 @@ final public class Author: NSManagedObject, Identifiable {
205205In the `Author`'s extension to conform to `SelfDescribingCoreDataEntity` we would set `isOrdered` to `false` or simply write `.toMany` :
206206```Swift
207207extension Author: SelfDescribingCoreDataEntity {
208- public static var entityDescription = Author.description (
208+ static var entityDescription = Author.description (
209209 // ...
210210 .relationship (\._books , .init (
211211 inverse : \Book.author ,
0 commit comments