Re: Strange NSZombie occurring
Re: Strange NSZombie occurring
- Subject: Re: Strange NSZombie occurring
- From: Andy Lee <email@hidden>
- Date: Sun, 07 Aug 2011 10:25:50 -0400
On Aug 7, 2011, at 9:10 AM, Scott Steinman wrote:
> -(void)setUp
> {
> words = [[self wordsFromPhrase:phrase]] retain];
> [self start];
> }
Is this your exact code? You use wordsFromPhrase: here but the method below is wordsInPhrase:.
> -(NSArray *)wordsInPhrase:(NSString *)thePhrase
> {
> NSArray *wordArray;
>
> [wordArray arrayByAddingObjectsFromArray:[phrase componentsSeparatedByString:@" "]];
> numWords = [wordArray count];
> return wordArray;
> }
Some problems with this method:
* You are sending arrayByAddingObjectsFromArray: to an uninitialized variable. The fact that you aren't crashing is pure luck.
* You are not assigning the result to anything.
* A design quibble: there's no real reason for the numWords instance variable. It's simpler to call [words count] when you need this number, and you don't have to worry about keeping two instance variables in sync.
>
> - (void) start
> {
> currentWordIndex = 0;
> wordChangeTimer = [[NSTimer scheduledTimerWithTimeInterval:wordChangeInterval
> target:self
> selector:@selector(changeWords:)
> userInfo:nil
> repeats:YES] retain];
> }
>
> - (void)changeWords:(NSTimer*)theTimer
> {
> currentWordIndex += 1;
> if (currentWordIndex > numWords)
> currentWordIndex = 0;
> messageLayer.string = [self.words objectAtIndex:currentWordIndex];
> }
This should be
if (currentWordIndex >= numWords)
And again, there's no reason not to say:
if (currentWordIndex > [words count])
> Now, the strangeness: words exists and is OK in setUpDisplay and startDisplay in that it contains the right words from the phrase. But in changeWords:, somehow words is nil.
To echo Keary: how do you know? It helps to know how you are diagnosing the problem.
--Andy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden