0

For a JSON request to a server, I am using some code that includes a value for the length of a string as follows:

[request addValue:[NSString stringWithFormat:@"%d", [body length]] forHTTPHeaderField:@"Content-Length"];

This code, however, is throwing a warning that %d should not be used for the length and the code be changed to %lu(unsigned long).

I am following the accepted answer here and numerous other places that says:

NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]]; 

Should I follow Xcode's suggestion? I am a bit reluctant to change working code as I have found XCode's suggestions to occasionally cause unintended problems.

Thanks in advance for any suggestions

user6631314
  • 1,751
  • 1
  • 13
  • 44
  • 1
    It's related to 32 vs 64 bits. Nowadays, with all iDevices supported by current XCode version being 64 bits, you'll get the warning. Note, that you can use a little trick: `@"%@", @(postData length)]` – Larme Aug 09 '18 at 07:09
  • I used your trick and it got rid of warning – user6631314 Aug 11 '18 at 17:30

0 Answers0