RE: pointer value into floating point value???HELP???
RE: pointer value into floating point value???HELP???
- Subject: RE: pointer value into floating point value???HELP???
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Thu, 28 Aug 2003 09:54:42 -0400
>
float ws1R;
>
float ws1G;
>
float ws1B;
>
>
timerValue = [[dictws1 objectForKey: @"R"]retain];
>
ws1R = [timerValue intValue];
>
[timerValue release];
Why are we retaining and releasing here? Indeed, why are we using an extra
variable like timerValue? We just want the integer value of the object in
the dictionary with the "R" key. Why not:
ws1R = [[dictws1 objectForKey: @"R"] intValue];
etc.
On the other hand, if we have the slightest doubt about whether there is
such an object in the dictionary we should do something like this:
timerValue = [dictws1 objectForKey: @"R"];
ws1R = timerValue ? [timerValue intValue] : 0;
or, if we have the slightest doubt about whether the object in the
dictionary has an intValue:
ws1R = (timerValue && [timerValue respondsToSelector:@selector(intValue)]) ?
[timerValue intValue] : 0;
There's no retaining or releasing in any of this.
Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.