So here is a problem.
I have a string
Белый Клык-0.fb2
NSString method length return 16
After save string in Core Data (backend - sqlite)
NSString method length return 17, but visually string stay the same
Белый Клык-0.fb2
And obviously method isEqualToString: return NO
After spent a lot of time in experiments, i am fugure out that problem is this letter:
й
Removing this letter solve problem.
But it is keeping driving me crazy, why something like that is happening?
Here workaround that works, but dont satisfy me:
And here workaround that dosnt works:
Please help me understand what is going on with string after save in Core Data.
And there is more elegant solution that i did?
The issue might be related to unicode normalization. So Coredata seems to store the string decomposed (so й
counts for 2 - one for the letter and one for the accent) and this is why you get the difference in length. If you try to decompose your original string before comparing it to what Coredata returns, it should work:
[yourOriginalString decomposedStringWithCanonicalMapping]
Now, the reason behind this is beyond my field of expertise. I constantly use coredata for managing my models and have worked multiple times with Greek / Russian strings and never had such an issue. If anyone can expand on this and shed some light I would be also very interested in the subject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With