All this seems overly complicated. Why doesn't +modelForDocument do it
automatically? It has the information from the modelFactory. It uses it to
load a model of the right type from the document, it would make sense that
it saves a document with the right type from a model, don't you think?

---
Sébastien Arbogast
http://sebastien-arbogast.com

2015-01-06 16:39 GMT+01:00 Mark <[email protected]>:

> You'll either have to do it in -initWithDocument, -didLoadFromDocument or,
> as of 1.1, -awakeFromInitializer (see FYI: CBLModel API change [iOS]).
>
> Depending on how you create your model, you can use the "isNew" flag to
> see if the model's underlying document is new and set type. Note that if
> you create your document yourself and then create a model (say if you need
> your own docID) you'll have to either check if type is already set and then
> set it.
>
> I haven't tried this in swift yet, but it works in Obj-C.
>
>
> On Jan 6, 2015, at 7:25 AM, Sebastien ARBOGAST <
> [email protected]> wrote:
>
> > I have device a model class that extends CBLModel. I have also
> registered this class with database.modelFactory. I was hoping that thanks
> to that, the type property of my document would be set automatically when I
> create it using let book = Book(newDocumentInDatabase:database), but it is
> not. And I tried overriding init like specified in the doc:
> >
> > init!(document: CBLDocument!) {
> >
> >         super.init(document: document)
> >
> >         self.type = "book"
> >
> >     }
> >
> > But the Swift compiler complains that it cannot find the CBLDocument
> class. Did I miss something?
> >
> > ---
> > Sébastien Arbogast
> > http://sebastien-arbogast.com
> >
> > --
> > 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/CAG1DMa_CnZJ4daE_KMTwVbm-th_v9DQMCUEeEPmZ2ya8Wvd1QA%40mail.gmail.com
> .
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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/9873C0AE-3A3D-43FF-AFED-BD42E35FA2A0%40gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAG1DMa8Pu9XKumpEzt9080n675MqQM0K-qZgBAfBxGt_2Qwzmw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to