good guy
good guy

Reputation: 569

iPhone: can i have a solution for converting NSNumber into NSString

hi i am working for Twitter client, i want display number(NSNumber) on UILabel like follower count, tweet, friends counts etc

this is delegate to store user Profile Data in NSArray it contains all info like user name and screen name and no. of followers, messages, status count, following this detail i have to display on respective Labels

- (void)userInfoReceived:(NSArray *)userInfo 
              forRequest:(NSString *)connectionIdentifier    
{
NSLog(@"User Info Received: %@", userInfo);    
NSMutableDictionary *profileData = [userInfo objectAtIndex:0];
                             // userInfo is converted into NSDictionary
lblUserName.text = [profileData objectForKey:@"name"];
                             // user name is displaying on lblUserName UILabel

and here lblUserName - UILabel, profileData - NSDictionary, userInfo - NSArray

On UILabel i have to display user follower count no

how i have to work with this

Upvotes: 0

Views: 973

Answers (4)

Tate Johnson
Tate Johnson

Reputation: 3950

You should use stringWithFormat which behaves similar to printf. That is, you can pass a string with placeholders that are interpolated.

NSNumber *number = [NSNumber numberWithInt:100];
NSString *string = [NSString stringWithFormat:@"%d followers", [number intValue]];
NSLog(@"%@", string); // Would print "100 followers\n"

Upvotes: 2

justin
justin

Reputation: 104708

[NSNumber stringValue] is good

Upvotes: 3

Di Wu
Di Wu

Reputation: 6448

NSNumber has an instance method called integerValue, which can convert an NSNumber object into a NSInteger. Then you can use NSString's stringWithFormat to convert that NSInteger into an autoreleased NSString.

Upvotes: 0

Nickolay Olshevsky
Nickolay Olshevsky

Reputation: 14160

You should use [NSString stringWithFormat]

Upvotes: 0

Related Questions