I have a simple yet frustrating problem.
I have this line in my app:
[super setText:[[[NSString alloc] initWithFormat:@"%i" arguments:arg] autorelease]];
That line was from a 3rd party library so I trying to just get rid of the warning and make it work properly. Anyway how would I fix this warning?
Thanks!
Full method:
- (void)timerLoop:(NSTimer *)aTimer {
//update current value
currentTextNumber += currentStep;
//check if the timer needs to be disabled
if ( (currentStep >= 0 && currentTextNumber >= textNumber) || (currentStep < 0 && currentTextNumber <= textNumber) ) {
currentTextNumber = textNumber;
[self.timer invalidate];
}
//update the label using the specified format
int value = (int)currentTextNumber;
int *arg = (int *)malloc(sizeof(int));
memcpy(arg, &value, sizeof(int));
//call the superclass to show the appropriate text
[super setText:[[[NSString alloc] initWithFormat:@"%i" arguments:arg] autorelease]];
free(arg);
}
Why not change it to:
NSString *text = [NSString stringWithFormat:@"%i", arg];
[super setText:text];
This assumes that arg
has a type of int
.
You would only use initWithFormat:arguments:
if arg
is actually is a va_list
from a variable argument list.
Update: Based on the updated code you posted you can do:
- (void)timerLoop:(NSTimer *)aTimer {
//update current value
currentTextNumber += currentStep;
//check if the timer needs to be disabled
if ( (currentStep >= 0 && currentTextNumber >= textNumber) || (currentStep < 0 && currentTextNumber <= textNumber) ) {
currentTextNumber = textNumber;
[self.timer invalidate];
}
//update the label using the specified format
int value = (int)currentTextNumber;
[super setText:[NSString stringWithFormat:@"%i", value]];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.