1

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> = []
} 
1
  • 1
    Make it either a transformable type or create a new entity and make to many relations to some Clip model. Commented Dec 12, 2014 at 16:51

1 Answer 1

3
//  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: data model

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":

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.