Reputation: 21
I have the following code:
long mins = 02; long secs = 35;
NSString *allTime = [[NSString alloc]init];
allTime = @"%i:%i",mins, secs ;
But it doesn't work, because when I try to display that nsstring object I got this: %i:%i Instead of that I want to get: 02:35
How to do that ? Thank you!
allTime = [NSString stringWithFormat:@"%l/%l", mins, secs];
for(Playlists *thePL in collection)
{
NSLog(@"===NEXT PLAYLIST===");
NSLog(@"Name: %@", thePL.namePL);
NSLog(@"Quantity of songs: %i", thePL.entries);
NSLog(@"Total of time: %@",thePL.allTime);
}
TOTAL OF TIME: l
Upvotes: 0
Views: 146
Reputation: 280
first you should read the calss reference of NSString. second, you should use this code:
NSString *allTime = [stringWithFormat:@"%d,:%d", mins, secs]
you can also to alloc the string and then initialize it by this way:
NSString *allTime = [[Nsstring alloc] init];
allTime = [NSString stringWithForat:@"%d:%d", mins, secs];
although, the best, the short and the better way is the first one. hope this help...
Upvotes: 0
Reputation: 1640
Try:
NSString *allTime = [NSString stringWithFormat:@"%d:%d",mins, secs];
Upvotes: 3
Reputation: 61341
long mins = 02;
long secs = 35;
NSString *allTime = [[NSString alloc] initWithFormat: @"%d:%d", mins, secs];
Upvotes: 4
Reputation: 50697
You need to use stringWithFormat
, see the NSString Class Reference
.
allTime = [NSString stringWithFormat:@"%d:%d",mins, secs];
Upvotes: 6