Its not so much a Cocos2D problem, but I figured you guys could help anyway. Basically I declared an NSArray in the header of a Scene. Initialized it in the init method, then tried calling it in a scheduled method but it crashes. Apparently the data is not carrying over or something. It works fine in the method itself; I can access the data in the init just fine, and likewise, if I initialized it in the scheduled method I can access it in there fine
NSArray help
(6 posts) (4 voices)-
Posted 2 years ago #
-
Dude, some code maybe?
an example:
//myArray is a member variable or possibly a global NSDate *aDate = [NSDate distantFuture]; NSValue *aValue = [NSNumber numberWithInt:5]; NSString *aString = @"a string"; myArray = [NSArray arrayWithObjects:aDate, aValue, aString, nil]; [myArray retain]; //did you forget to retain?Posted 2 years ago # -
Apparently yes, not so much that I forgot to retain, as I didn't know I had to do that, I'm a beginner in Objective-C
In the header I had this
@property(nonatomic, retain) NSArray* nsa;
I thought that was enough, and I never had an issue needed to manually retain
thanks for the helpPosted 2 years ago # -
ok, if its a @property(nonatomic, retain) then do this instead:
self.nsa = [NSArray arrayWithObjects:aDate, aValue, aString, nil]; //no need to retainthe setter isnt used unless you use 'self.'
Posted 2 years ago # -
[moved to "e.else" from "cocos2d"]
Posted 2 years ago # -
or you can just use alloc
myArray = [[NSArray alloc] initWithObjects:aDate, aValue, aString, nil];
Posted 2 years ago #
Reply
You must log in to post.