I see that you're assigning an autoreleased object to your class variable. If you're using an ivar, you'll have to retain this information yourself. It's easier to use a property where you can declare it as retain. Here's how:
In your .h
@interface MyClass {
NSArray *orderItems;
NSDictionary *list;
}
@end
Becomes:
@interface MyClass
@property (nonatomic, retain) NSArray *orderItems;
@property (nonatomic, retain) NSDictionary *list;
@end
In your .m file, in your jsonTapped
method:
orderItems = [str objectFromJSONString];
list = [orderItems objectAtIndex:0];
becomes:
self.orderItems = [str objectFromJSONString];
self.list = [orderedItems objectAtIndex:0];
You could also do this:
orderItems = [[str objectFromJSONString] retain];
list = [[orderItems objectAtIndex:0] retain];
But then, you'll have to remember to release them somewhere otherwise you'll have a memory leak.
For properties, it's as simple as setting them to nil
. The compiler will know to release the object when necessary.
Here's what your dealloc
method should look like:
- (void)dealloc {
self.orderItems = nil;
self.list = nil;
...
[super dealloc];
}