FYI: CBLModel API change [iOS]

31 views
Skip to first unread message

Jens Alfke

unread,
Dec 19, 2014, 5:37:21 PM12/19/14
to mobile-c...@googlegroups.com
[You can ignore this if you don't develop for iOS, don't use CBLModel, or don't build your own CBL from source.]

Pasin and I have made a small change to the CBLModel API, on the master branch of couchbase-lite-ios. (This change will appear in the forthcoming 1.1 release.)

To quote from issue #521:  "-initWithDocument: is dangerous: it can be called with a nil document by accident, which leaves the instance in a confused state where it will later fail assertions, e.g. when you set properties on it. The documentation for -initWithDocument: tries to spell out how it's safe to use it, but doesn't really; it's just too confusing."

To prevent this, we've removed the initializer methods from CBLModel's public API. The changes you'll need to make to your code are:
• Change calls like [[MyModel alloc] initWithNewDocumentInDatabase: db] to [MyModel modelForNewDocumentInDatabase: db].
• If your model subclass overrides -initWithDocument:, in order to initialize its own state, it should instead override the new method -awakeFromInitializer, which will be called when an instance is initialized.

—Jens
Reply all
Reply to author
Forward
0 new messages