Search code examples
objective-cxcode4nsstringint

Display NSTimer Count in UILabel


I'd like to show my countdown for a process to load, and understand that it is disallowed using ARC to convert an int to an NSString. How can I show my count within an NSString?

static int count = 0;
count++;

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:(5.0) 
                          target:self 
                          selector:@selector(uploadData) 
                          userInfo:nil 
                          repeats:NO];

if (count <= 5)
{
    ilabel.text = @"Please be patient...";
    NSString *counter = count;
    counterLabel.text = counter;
}

Solution

  • Probably the easiest way to do this is:

    NSString* counter = [NSString stringWithFormat: @"%d", count];