@interface Note : CBLModel
@property (copy) NSString* text;
@property NSDate* created;
@property bool checked; // bool not BOOL! See below for why
@end
And here's the implementation of the class:
@implementation Note
@dynamic text, created, checked; // marks these as persistent
@endOn Oct 15, 2014, at 12:44 AM, Karel-Jan Van Haute <kare...@gmail.com> wrote:Can someone provide me with a small example on how to implement the CBLModel in swift?
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)
}
}
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)
}
}