How to model a class that could be both referenced and embedded

How to model a class that could be both referenced and embedded? Should I create another object that confirms to CBLJSONEncoding?

For example, display a list of all tags by reference, and also embed selected tags in a note class.

class Note: CBLModel {
@NSManaged tags: [Tag] <- want to embed this property not reference, but also need to reference it elsewhere.
}

class Tag: CBLModel {

}

Is this the recommended solution:

class Note: CBLModel {
@NSManaged tags: [NoteTag]
}

class Tag: CBLModel {

}

class NoteTag: NSObject, CBLJSONEncoding {
static func noteTagWithTag(tag:Tag) -> NoteTag { }
}

You can’t do this with a single class, unfortunately.

To be referenced, the class has to inherit from CBLModel. But CBLModel expects that it owns a document, so it can’t be used for embedded objects.

This would be a good use case for multiple inheritance, if Swift (or Obj-C) supported it. As it is, you’ll have to make two different classes. You could define an interface that defines the properties, and then have both classes implement it — this will make sure the properties stay consistent between the two.

Ok thanks, I’ll define an interface for this case.