Automatic Reference Counting Issue: Cast to 'NSString *' of a non-Objective-C to an Objective-C pointer is disallowed with Automatic Reference Counting
I can't seem to find out how to cast things properly, despite many threads and such saying this kind of thing is what you do.
I've thought of a way around (making my own class and using replaceCharactersInRange) but I don't think this is very elegant, and I'd still prefer to use this method :/
What I got from that is that displaying it with NSLog has issues not the method. I've used it plenty of times and it worked fine. Try printing the result in a text file and see if it's ok.
Why does it crash? What's the output in the console. Why can't it write to a file?! Are you checking the error object after any of these operations? Rarely does something "just not work", there's plenty of things to check and try to find out what is failing and why.
Why does it crash? What's the output in the console. Why can't it write to a file?! Are you checking the error object after any of these operations? Rarely does something "just not work", there's plenty of things to check and try to find out what is failing and why.
Forget writing to a file for a second. It crashes because when the connectionDidReceiveData (because I'm using NSURLConnection) delegate method is called, there is no data to write (because the string isn't escaped). I've looked at whats in the NSLog, escaped all the characters myself, entered it into safari, and it works, so it obviously isn't being escaped.
Is stringByAddingPercentEscapesUsingEncoding returning an object or is it nil? If it returns an object, what are the contents? Print it out to a file (use the writeToFile:atomically:encoding:error: method of NSString and watch the error object to see if and why it fails to write) or NSLog (if it works) and see what exactly it gives you. If it's nil, what's in the 'string' object? Is that by any chance nil? If not, what are its contents? What is the exact reason for the crash (post the crash log)?
Well, if you're not willing to debug your own code thoroughly I'm not sure what more to say.
Is stringByAddingPercentEscapesUsingEncoding returning an object or is it nil? If it returns an object, what are the contents? Print it out to a file (use the writeToFile:atomically:encoding:error: method of NSString and watch the error object to see if and why it fails to write) or NSLog (if it works) and see what exactly it gives you. If it's nil, what's in the 'string' object? Is that by any chance nil? If not, what are its contents? What is the exact reason for the crash (post the crash log)?
Well, if you're not willing to debug your own code thoroughly I'm not sure what more to say.
Yes, stringByAddingPercentEscapesUsingEncoding is returning an object, however it hasn't changed in the text file.
The reason for the crash is EXC_BAD_ACCESS, but I stepped through the code (a few hours ago), and found out that the error is when I do this:
Is data in that method nil? If so, don't append it. Are you sure your reference to responseData is ok and not deallocated? Can you post the string before and after calling escape?