Re: Strange NSZombie occurring
Re: Strange NSZombie occurring
- Subject: Re: Strange NSZombie occurring
- From: "Dr. Scott Steinman" <email@hidden>
- Date: Sun, 07 Aug 2011 11:51:20 -0500
Ah. I see some of your points. Very dumb of me. I'm new to Cocoa, but I did program in a number of other languages for 30 years. I apologize for not being clear enough. Pain and nausea tend to mess up the clarity of my thinking. Unfortunately, I'm ill most of the time (don't ask about my health. It's too depressing). This also makes it take an extremely long time to get any program done. In the past, I got into the habit of not asking for help, and forcing myself to figure out the solution on my own. I don't like to bother other people with my problems (besides, learning from my mistakes was the way I learned before). Maybe with Cocoa this is a bad idea.
>> Is this your exact code? You use wordsFromPhrase: here but the method below is wordsInPhrase:.
This is a typo. The same method names are used in my code. I tried to pare down the source code to a manageable length for posting my question. When I looked at it afterwards, I didn't notice my own typos. I always the a long time to check for such typos when within Xcode.
To give you a little more background about the context of the code snippets in the full program, I'm trying to animate the individual words of the phrase in sequence with fading in and out, color changes, etc. I'm using Core Animation in conjunction with the NSTimer because I could not find an elegant way to create an NSKeyframeAnimation in which each individual word of my phrase (displayed in a CATextLayer) could be swapped in sync with the other animatable properties. Each individual word had to be set before the animation started. My solution was to use the timer's changeWords: method to change the words and trigger a one-shot animation on each invocation, with the timer's duration slightly longer than the animation's duration. Yes, I know this is a kludge, but it was the only way that I could come up with to solve this problem. I ran it past a few other people and they thought it would work. Any other approaches would be appreciated.
> Another thing: you are ignoring the argument thePhrase.
Right. In paring down the code for my post, I passed an argument. In my working code, I simply use the phrase property within the method. Sorry about making that mistake and confusing the issue. And, yes, I am declaring ivars for all of the properties.
> phrase = @"This is the phrase to display"; // stringWithString: is almost never what you intend.
God, was that stupid! Of course I should have done that!
> Do you ever want to change .words without doing [self start]? If not, make the call to -start inside setWords:. Then self.words = [self wordsFromPhrase: self.phrase] can completely replace -setUp.
Good point. Within start: I call different methods for each type of animation to use, but I never change the words without calling [self start]. This would be a good place to move that call. I had not refactored my code yet.
> NSArray *wordArray;
> [wordArray arrayByAddingObjectsFromArray:[phrase componentsSeparatedByString:@" "]];
I did not notice that mistake. That _should_ crash. Thanks.
> and that you _really_ mean:
> @property(nonatomic, readonly) NSUInteger numWords;
> @property(nonatomic, readonly) NSArray *words;
> @property(nonatomic, retain) NSArray * backingWordsArray;
I thought that properties such as NSString and NSArray needed to be retained or copied. Am I wrong?
> wordChangeTimer = [[NSTimer scheduledTimerWithTimeInterval:wordChangeInterval
> [My customary objection to accessing an ivar directly.]
I tried both wordChangeTimer and self.wordChangeTimer when I was testing the program. Both worked, so I left it as is.
> self.wordChangeTimer = [NSTimer ... repeats: YES];
> If you let the property manage your memory, you won't have to do it yourself. And if you have a setter method, you can invalidate the old timer.
Would invalidating within the setter as the NSTimer is assign in the code above for the first time cause a problem?
> What are setUpDisplay and startDisplay? Are they the same as setUp and start?
Yeah. Another typo. You know, when I took a mandatory typing class in junior high school, I was the worst typist in the class. That's probably why I was also a terrible piano player.
I ran everything through the debugger, and stepped though it. That's how I knew that words had a non-nil value in start and not have it in changeWords:. As for Instruments, I find Apple's documentation very unclear. I've only used Instruments on one project before this, and managed to remove a leak. When I ran Instruments on this project, I did not notice a leak. However, since I'm so new to Instruments, it's entirely possible that I forgot how to use it properly again on this project. ;-) Is there a good tutorial on using Instruments? All I've seen on-line are descriptions of the tools within Instruments, but not clear instructions on how to use them.
I will take your advice and correct my code. I appreciate your patience with a noobie like me, especially with noobie stupid mistakes, and having the patience to help me despite the problems with the clarity of my thinking. That's one of the things that I appreciate about the Apple community. This was not always true with the other languages I used.
Thank you.
Scott
Sent from my iPad
_______________________________________________
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