iOS Development-Summary of common errors and warnings

Source: Internet
Author: User

NSString is one of the most commonly used classes, almost everyone can not leave, it is very powerful function, but it is a little mystery until the encounter to find.

Body:
There is a rangeofstring in NSString's API: This is also a common API to find in strings. I generally figure the easy, all with this, rarely used rangeofstring:option:


It was because of laziness that led me to a crash, I really remember deeply.
Next, let me give you an example:


Clearly there is a ":", the result is not found. This led me to the crash of my later code. This is not to say this crash, but to find out why, why this ":", can not find it.


Print length, unexpectedly is 2. Then why can't you find it? In a different way:


Got it!!!!!
The problem is solved, but why is it so?

This has to look at the composition of Unicode.
There are two forms of Unicode for composition: The form of synthesis and the form of decomposition.
And NSString's rangeofstring, this API support for this is the case. Rangeofstring, the default is not according to the code element to find, that is, not according to Literalsearch. Although it contains ":", however, these two characters can synthesize another character with its equivalent, so it is not found.

Some of the synthetic characters have a corresponding form in the Unicode character table, and some do not. I'm not going to give you an example. This is based on the specific rules of the various characters, such as the character + Cyrillic, you can set up a lot of strange characters.

Remind:
If you want to find characters in NSString, be sure to take option. Because NSString and Unicode still have a lot of pits.

iOS Development-Summary of common errors and warnings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.