I have a NSString that will be passed as a parameter to my library’s function, the NSString is passed by another library. The strange thing is, if I pass the NSString to the library call, the call will fail, but if I convert the NSString to int and then convert the int back to a NSString, every thing is fine.
But by printing it out using NSLog("%@"), the two strings are identical. What may cause this? Encoding?
When you
you are basically creating a copy of the string, unrelated to the original one.
It would be interesting to know how you create the two strings to know what exactly happens. My guess is that the first one is deallocated too soon, so the call fails; the copy is retained and the call succeeds.
Just for a quick try:
when calling the function that is failing:
just do:
If this works, then the memory management issue is confirmed, but for a real fix you should explain how you create the strings…