Change string length after saving to Core Data

So here is the problem.

I have a line

 -0.fb2 

NSString 16 method length return

After storing a row in Core Data (backend-sqlite)

The length of the NSString method returns 17, but visually the string remains the same

   -0.fb2 

And obviously, the isEqualToString method: return NO

After spending a lot of time in the experiments, I am sure that the problem lies in this letter:

   

Removing this issue resolves the issue.

But that keeps me crazy, why is something like this happening?

Here's a workaround that works but doesn't satisfy me:

  • stringByReplacingPercentEscapesUsingEncoding: - you need to convert the string directly to and after the db request
  • transliterate an entire line - kinda hack

And here is the workaround that dosnt works:

Please help me understand what happens to a string after saving to Core Data.

And is there a more elegant decision I made?

+4
source share
1 answer

The problem may be related to Unicode normalization . So, Coredata seems to keep the line spread out (so that it counts 2 - one for the letter and one for the accent), and that is why you get the difference in length. If you try to expand the original string before comparing it with what Coredata returns, it should work:

 [yourOriginalString decomposedStringWithCanonicalMapping] 

Now the reason is that it is beyond my competence. I constantly use coredata to manage my models and have worked many times with Greek / Russian strings and have never encountered such a problem. If someone can expand this and shed some light, I am also very interested in this matter.

+3
source

All Articles