I have this Swift class called ”aProject”. How can I convert this into a Core Data object - I’m stuck with the property ”clips” - an array.
class aProject = {
var name: string!
var id: Int32
var clips : array <String> = []
}
I have this Swift class called ”aProject”. How can I convert this into a Core Data object - I’m stuck with the property ”clips” - an array.
class aProject = {
var name: string!
var id: Int32
var clips : array <String> = []
}
// Project.swift
import Foundation
import CoreData
class Project: NSManagedObject {
@NSManaged var name: NSNumber
@NSManaged var id: String
@NSManaged var clips: NSSet
}
// Clip.swift
import Foundation
import CoreData
class Clip: NSManagedObject {
@NSManaged var name: String
@NSManaged var id: NSNumber
@NSManaged var projects: NSSet
}
Your NSManagedObjectSubclasses should look like this. You need to create relational data model with a clips entity and a project entity where there is a to many relationship between them. Your data model should look something like this:

Once you have set up the data model, the easiest way to get the subclass is to go to the editor tab on your top bar and select "create NSManagedObject Subclass". Select both entities and they should be created to look like the above classes. Finally, change the class for each entity in your data model to be "xxxxxxxxxxx.EntityName" where the xxxxxxxx is your project name and Entity name is either "Project" or "Clip":
