NSObject to NSString Objective-C

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

Answers (4)

Jevgenij Kononov
Jevgenij Kononov

Reputation: 1237

try this, it is worked for me

NSObject* obj= values[i];
NSString *StringObject= [NSString stringWithFormat:@"%@", obj];

Upvotes: 1

CStreel
CStreel

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

Williham Totland
Williham Totland

Reputation: 29039

Simpler still:

NSString *address = [ivpObj.addressStr description];

Upvotes: 3

Eimantas
Eimantas

Reputation: 49354

How about this:

NSString *address = [NSString stringWithFormat:@"%@", ivpObj.addressStr];

Upvotes: 9

Related Questions