Reputation: 265
Can someone help me to convert an NSObject to NSString?
I'm trying to do something like this -
NSString *address = [NSString stringWithFormat:ivpObj.addressStr];
But I got an warning - Format is not a string literal and no format arguments
Please some one help
Upvotes: 4
Views: 16484
Reputation: 1237
try this, it is worked for me
NSObject* obj= values[i];
NSString *StringObject= [NSString stringWithFormat:@"%@", obj];
Upvotes: 1
Reputation: 2642
it is giving you a warning because you are useing stringWithFormat and you are not passing in a format you just passing in either an NSString or a CString
so chose from on of the other options
[NSString stringWithString: ivpObj.addressStr]
[NSString stringWithCString: ivpObj.addressStr encoding: String_Encoding of you addressStr here]
[NSString stringWithUTF8String:ivpObj.addressStr]
this should remove your warnings, otherwise if you want to format the string using something similar to Eimantas's answer
Upvotes: 0
Reputation: 29039
Simpler still:
NSString *address = [ivpObj.addressStr description];
Upvotes: 3
Reputation: 49354
How about this:
NSString *address = [NSString stringWithFormat:@"%@", ivpObj.addressStr];
Upvotes: 9