forum

Home / DeveloperSection / Forums / Issue with NSString method initWithData: encoding: in Objective-C

Issue with NSString method initWithData: encoding: in Objective-C

Anonymous User 1254 13-Dec-2015

I have an issue with the initWithData: method of NSString, here is code:

NSData *dataObj = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *strObj = [[NSString alloc] initWithData:dataObj encoding:NSUTF8StringEncoding];

Here, problem with initWithData: is that it does't return an instance of NSString, I tried doing an explicit type-cast using (NSString *) as well without much luck. This is giving me compiler warnings when I try to pass the stringReply to a method I've written with type mismatches. Given I treat all warnings as errors, I'd really like to understand what stringReply is being returned as and how I can enforce it to be of type NSString.


Updated on 14-Dec-2015
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By