Out of scope variables after loading

1 view
Skip to first unread message

Sébastien

unread,
Apr 17, 2009, 4:30:28 PM4/17/09
to sqlitepersistentobjects-user
I'm using SQLitePersistentObject for an iPhone app.
One of my objects has several NSDate properties:

@interface Invitation : SQLitePersistentObject {
...
NSDate *finalStartDate;
NSDate *finalEndDate;
...
}

...
@property(nonatomic,assign) NSDate *finalStartDate;
@property(nonatomic,assign) NSDate *finalEndDate;
...
@end

I save an instance of this class with values for both properties, but
when I load it using the following query, the debugger tells me that
they are out of scope:

Invitation *invitation = (Invitation*)[Invitation findFirstByCriteria:
[NSString stringWithFormat:@"WHERE key='%@'",[attributeDict
objectForKey:@"key"]]];

As a result, I'm getting EXC_BAD_ACCESS errors when I try to use those
dates.

Any idea?

Adam Jack

unread,
Apr 17, 2009, 4:34:20 PM4/17/09
to sqlitepersiste...@googlegroups.com
Maybe an obvious question, but did you retain the object you loaded?

regards

Adam

David Sinclair

unread,
Apr 17, 2009, 4:48:22 PM4/17/09
to sqlitepersiste...@googlegroups.com

On Apr 17, 2009, at 13:30:28, Sébastien wrote:

> @property(nonatomic,assign) NSDate *finalStartDate;
> @property(nonatomic,assign) NSDate *finalEndDate;


Those should be:

@property(nonatomic, retain) NSDate *finalStartDate;
@property(nonatomic, retain) NSDate *finalEndDate;

You need to retain loaded properties, or it'll get autoreleased while
leaving an invalid pointer to it in the ivar.

--

David Sinclair, Dejal Systems, LLC - d...@dejal.com
Dejal blog - http://www.dejal.com/blog/
Cocoa code - http://www.dejal.com/developer/
Twitter - http://twitter.com/dejal/


Adam Jack

unread,
Apr 17, 2009, 4:52:16 PM4/17/09
to sqlitepersiste...@googlegroups.com
Doh, and I looked right at those to check for that. Guess I am blinded by the bright two foot of snow we have.

Adam

Sebastien ARBOGAST

unread,
Apr 17, 2009, 5:06:45 PM4/17/09
to sqlitepersiste...@googlegroups.com
Thanks you so much David! This was exactly that.
Reply all
Reply to author
Forward
0 new messages