Bright Future
Bright Future

Reputation: 227

Is this an attribute of an entity?

I defined an entity Person:

class Person: NSManagedObject {

@NSManaged var firstName: String
@NSManaged var lastName: String

}

Then:

let person = NSEntityDescription.insertNewObjectForEntityForName(entityName, inManagedObjectContext: managedObjectContext!) as! Person

        person.firstName = "First name"
        person.lastName = "Last name"

Now I'm confused, is person an attribute like firstName and lastName? What is insertNewObjectForEntityForName?

Upvotes: 0

Views: 40

Answers (2)

M Zubair Shamshad
M Zubair Shamshad

Reputation: 2741

So you defined an entity named: Person ,

Person is a subclass of type NSManagedObject. This Person has attributes firstname & lastname.

if you are asking about the person (lowercase), it is an instance of your class Person (entity).

and insertNewObjectForEntityForName is the method of NSManagedObject Class to Insert every new managed Object record in DB. It will create a new records Row in your data table.

Upvotes: 1

rounak
rounak

Reputation: 9397

A CoreData db can have many types of entities. Person is one such entity. A Person entity has attributes firstName and lastName.

Hope that clears it up.

Upvotes: 0

Related Questions