stringByAddingPercentEscapesUsingEncoding was deprecated in 9.0 .How to do this?

后端 未结 5 733
野性不改
野性不改 2020-12-29 03:56

I\'m a junior developer, and I got a code for this:

(NSString *)encodedStringFromObject:(id)object {
    return [[object description] stringByAddingPercentEs         


        
5条回答
  •  灰色年华
    2020-12-29 04:54

    You'd read the spec for both functions. Then you would find out for what purpose characters are replaced with escape sequences. From there you would find out the set of allowed characters, which must be documented somewhere.

    That's an essential part of changing from junior to normal to senior developer: Find out exactly what your code is supposed to do, which should be defined somewhere, and then make it do what it should do.

    stringByAddingPercentEscapesUsingEncoding is probably deprecated because it doesn't know which characters are allowed and sometimes gives the wrong results.

提交回复
热议问题