Sending cStringUsingEncoding:
to encodedString
can only work if encodedString
is an NSString object. Having an NSString object is the point you're trying to get to. Moreover, that method does not decode the string, it encodes the string using the encoding you ask for; thus, in the code you show, you ask for the (already-encoded) string to be encoded in some random encoding (the default C string encoding), then attempt to decode the result as UTF-8. That won't work.
You don't specify what type you're using for encodedString
. Either way, you need to create the NSString object by passing encodedString
and its encoding.
All of these except initWithUTF8String:
require you to specify the encoding (initWithUTF8String:
does by definition), and all of them except initWithData:encoding:
come in an autoreleasing convenience version (+stringWith…
instead of -initWith…
).