receive notification when SQLitePersistentObject is saved

2 views
Skip to first unread message

kenji

unread,
Mar 16, 2010, 10:30:12 PM3/16/10
to sqlitepersistentobjects-user
Hi

I've started using sqlpo for an iphone project and I love it!

Is there a way to receive a notification right after
SQLitePersistentObject is saved?

I did a workaround and it worked :

1. create a transient saveCount property
2. override save
- (void) save {
[super save];
self.saveCount += 1;
}
3. register key-value observing for saveCount, using
addObserver:forKeyPath:options:contex

but I'm looking for a better solution.

regards
Kenji

Andrew W. Donoho

unread,
Mar 17, 2010, 1:31:10 PM3/17/10
to sqlitepersiste...@googlegroups.com, kenji

On Mar 16, 2010, at 9:30 PM, kenji wrote:

> I've started using sqlpo for an iphone project and I love it!

Good.

> Is there a way to receive a notification right after
> SQLitePersistentObject is saved?
>
> I did a workaround and it worked :
>
> 1. create a transient saveCount property
> 2. override save
> - (void) save {
> [super save];
> self.saveCount += 1;
> }
> 3. register key-value observing for saveCount, using
> addObserver:forKeyPath:options:contex


It really depends upon the granularity you need for the notification. There are many mechanisms you could use. If the above is sufficient, then go with it. That said, since you are not actually observing an ivar, why aren't you using the NSNotificationCenter? You could then dispense with the transient variable. NSNotification supports instance level observing.

Anon,
Andrew
____________________________________
Andrew W. Donoho
Donoho Design Group, L.L.C.
a...@DDG.com, +1 (512) 750-7596

"We did not come to fear the future.
We came here to shape it."

-- President Barack Obama, Sept. 2009

Kenji Tayama

unread,
Mar 17, 2010, 9:34:35 PM3/17/10
to Andrew W. Donoho, sqlitepersiste...@googlegroups.com
Thanks for the advice.

NSNotification seemed complicated to use at first sight
(I am new to Objective-C / Cocoa), but now that you've
recommended it and I looked in some more,
I guess I'll go this way.

Thanks,
Kenji


2010/3/18 Andrew W. Donoho <andrew...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages