NSDATA description returning nil - ios

NSData description returning nil and making the NSData object nil. My code has stopped working and I would like to get this working again.
If I compile my code in Xcode 10 it will get the NSData description fine. But if I use Xcode 11 it will give me nil as the description and it will make the NSData nil as well. I'm confused as to how this is happening. Is this because it's still a beta release? Is this kind of thing normal in beta releases? I just want to make sure my code still works before the new iOS 13 an iPAD OS 13 come out.
NSString *result = [[data description] stringByReplacingOccurrencesOfString:#" " withString:#""];

See https://twitter.com/steipete/status/1174111017900503040 - iOS 13 behavior (written at time of GM seed 2).
As others have said, you should not be using [NSData description] this way.

Related

When I convert NSData to NSDictionary,there showed something different on iOS9 and iOS8

On iOS 9 the result is what I want,however,on iOS 8,the dictionary is not a real dictionary.The two pictures is on iOS 9 and iOS 8.What's more,on iOS 10,it's fine.
I wonder how can I convert NSData to NSDictionary correctly on iOS 8.
I use AFHTTPClient to get data.
The response object is already a dictionary! AFNetworking did handle that for you .
print the log of responseObject which you getting from response :
https://stackoverflow.com/a/19086685/3901620

UIWebView using loadData compile error

I have NSData in Core Data stored, could be image, rtf, video or text. I am trying to use UIWebView to show the NSData using loadData, but the build give me the error message:
No visible #interface for 'UIWebView' declares the selector 'loadData:MIMEType:textEncoding:baseURL:'
This is my code for RTF:
UIWebView *wv = [[UIWebView alloc] initWithFrame:view.bounds];
NSData *data = entry.data;
[wv loadData:data MIMEType:#"application/rtf" textEncoding:#"utf-8" baseURL:nil];
[view addSubview:wv];
I have seen a lot of links how to use this and also Apple Documentation explains it. Why I am getting the build error? iOS Development Target is 7.0
The comments in this link say to not pass a nil value for the base URL. Try replacing nil with even just #"https://"
I have restarted my MacBook and also Xcode, cleaned the project and the error is gone - very strange, but now it works fine.

Converting NSData to NSString returns nil

I know this question is asked before, but none of the solutions worked for me. I am trying to convert an NSData object to a NSString value. I am initing the NSString object like following:
NSString *html = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
But the html is always nil. The NSData I am trying to convert is the source code of a website. It is fairly long. This is 'NSData` I am trying to convert.
Is it the length of the data that is causing the issue? I need the source code as a string. What can I do to resolve this issue?
What I tried so far:
Tried with all encoding formats as shown in this answer.
Tried with [NSString stringWithUTF8String:[urlData bytes]];
But whatever I do produce the same result. html always is nil whatever I do.
EDIT
It was a problem with the debug console. Even when the objects had values in it, the debug console always showed nil as the value for most of the objects. However NSLog always displays the value.
It's not a problem with debugger
The problem comes from compiler optimization, compiler see that string was not directly used, and optimizes the code by removing it and directly passing it to another method.
The key of the problem : You are running project on release scheme
Solution:
Here is a small guide to switch project to the Debug scheme
1) Click on the target, and click Edit scheme...
2) Popup will be displayed
3) Click Run %Your project%
4) Open Build Configuration popup
5) Select Debug
5) Press OK
6) You are ready to Go!, now you can debug anything :)
If you are using ARC, and you just wrote the code that converts the data to a string and haven't written any code yet that actually uses the string, it will get deallocated immediately. Check whether that is what is happening. For example, what does NSLog (#"%#", html) display?
NSAttributedString *str = [[NSAttributedString alloc] initWithData:data options:#{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]}
documentAttributes:nil error:&error];
Try this one:
NSString *myString = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
Generally, conversion from NSData to NSString returns nil means there is mismatch between encoding format received from server and approach used for encoding.

SQLite show strange signings when none english chars are stored in tables

Im coding an iPad App heavily using SQLite 3, I'm able to insert data in Hebrew, i downloaded the Data Base to both Mac and Windows and i was able to see the Hebrew content, but when i retrieve it on the iPad i see chars without meaning like you see in the picture attached,i was trying to look for an answer for few days and i cant find an answer, only questions, can anyone help on this?
Im using this code to get the SQLite results and put it in an NSString
d.Visit_Date = [NSString stringWithFormat:#"%s",sqlite3_column_text(statement, 1)];
d.Visit_Reason = [NSString stringWithFormat:#"%s",sqlite3_column_text(statement, 2)];
d.Visit_Result = [NSString stringWithFormat:#"%s",sqlite3_column_text(statement, 3)];

Issues getting json from webserver in iOS5

I have a app that receive a feed from a server through json.
I have been building it for iOS5, but in the last weeks testing with iOS6. I tested today with a iOS5 device, and everything crashed.
The code looks like this:
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.myserver.com/news.json"]];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
It worked without problems, but now it returns a null. The data is not null.
Cocoa error 3840 means
The data couldn’t be read because it has been corrupted. (No string
key for value in object around character 2.)
You should check your json with a validator like http://www.jsoneditoronline.org/ or http://jsonformatter.curiousconcept.com/
The issue was a duplicated key from the webserver. Now it works.
But it strange that the error is trigged in iOS5 and not in iOS6.

Resources