0

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:@""];

Manoj Rlogical
  • 239
  • 1
  • 4
JC Castano
  • 135
  • 1
  • 6
  • 2
    You shouldn’t be using `description`, you should convert the data to a string properly. – Aaron Brager Jun 27 '19 at 13:31
  • 1
    It's not recommended to use `description`, not at all. Apple could decide to change the output, and tomorrow it might print ` ` and break your code. Instead look how to convert NSData to Hex String: https://stackoverflow.com/questions/1305225/best-way-to-serialize-an-nsdata-into-a-hexadeximal-string etc. – Larme Jun 27 '19 at 13:34
  • Possible duplicate of [Best way to serialize an NSData into a hexadeximal string](https://stackoverflow.com/questions/1305225/best-way-to-serialize-an-nsdata-into-a-hexadeximal-string) – Larme Jun 27 '19 at 13:36
  • I highly doubt that calling `[data description]` is causing your `NSData` object to be nil. I'd look more into where you're getting that `NSData` from and set a break point immediately after you're `NSData` object gets created to ensure that it actually exists and if it doesn't look into why the object is being set to nil. – tww0003 Jun 27 '19 at 17:28

1 Answers1

1

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.

xaphod
  • 6,392
  • 2
  • 37
  • 45