Search code examples
iosswiftinheritancecloudkitckrecord

CloudKit Record Type Inheritance


I am starting out on adding CloudKit to my iOS app. I have a fully completed data model already that was implemented using Core Data. I used inheritance for my NSManagedObject classes. Is that something I can also do with a CloudKit schema? For example, can I make an Employee RecordType inherit from a Person RecordType?

class Person: NSManagedObject {

  @NSManaged var uuid: NSUUID!
  @NSManaged var birthday: NSDate
  @NSManaged var name: String?
  @NSManaged var age: Int16
}

class Employee: Person {

  @NSManaged var salary: Int16
}

Solution

  • Cloud Kit record types are more like database tables. There's no such concept as classes or inheritance. A record type simply has 1 or more fields.

    If you wanted an Employee record type you would need to have fields for salary, uuid, birthday, name, and age in that one record type.