Ok I think I have it.
So I will post my solution here for the lost ones.
I'm not sure this is the right way to do it. But it works for now.
I've made a general Model that adds created date and the last modified date.
import Foundation
typealias CBLDoc = CBLDocument
class Model: CBLModel{
@NSManaged var created: NSDate
@NSManaged var last_modified: NSDate
init(inDatabase database: CBLDatabase, ofType type: String){
super.init(document: self.document)
self.database = database
self.created = NSDate(timeIntervalSinceNow: 0)
self.last_modified = NSDate(timeIntervalSinceNow: 0)
self.setValue(type, ofProperty: "type")
}
override init(document: CBLDoc) {
super.init(document: document)
}
}
And then you have a Person class that inherits from the general Model
import Foundation
class Person: Model{
@NSManaged var owner: String
@NSManaged var nickname: String
@NSManaged var status: String
@NSManaged var testing: String
let type = "person"
init(inDatabase database: CBLDatabase, withNickName name: String, owner:
String){
super.init(inDatabase: database, ofType: type)
self.owner = owner
self.nickname = name
self.status = "active"
}
override init(document: CBLDoc) {
super.init(document: document)
}
}
I hope this is the way to go.
On Wednesday, October 15, 2014 5:29:54 PM UTC+2, Jens Alfke wrote:
>
>
> On Oct 15, 2014, at 12:44 AM, Karel-Jan Van Haute <[email protected]
> <javascript:>> wrote:
>
> Can someone provide me with a small example on how to implement the
> CBLModel in swift?
>
>
> Search the list archives for "swift" and you'll find a few prior threads
> about using CBLModel, including the syntax for declaring dynamic properties
> in Swift.
>
> I have only had time to do a little bit in Swift; I ported Grocery Sync
> but haven't yet gotten around to working with CBLModel in it.
>
> —Jens
>
>
--
You received this message because you are subscribed to the Google Groups
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/mobile-couchbase/9d2f4bdb-0d85-4a65-9c7a-3fb657afa552%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.