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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to