(Turn) [ios] Determine whether UITextField.text is empty

Reprinted from: http://bbs.9ria.com/thread-235206-1-1.html

 

Judging that the NSString string is empty is a problem that almost every developer will encounter. For most people, the first thing that flashes to the brain is the following method

  1. if([yourTextString isEqualToString:@""])
copy code

But unfortunately, such judgments often fail, resulting in many inexplicable bugs. For example, if this method is used to judge whether the UITextField is empty, there will be problems.

  1. [yourTextField.text isEqualToString:@""] || yourTextField.text == nil
copy code

Although the above line of code can work normally, it is a bit depressing to have to write such a line of code every time. In fact, there is a simple and clear workaround method, which I recommend everyone to use:

  1. yourTextField.text.length == 0
copy code

Original link: http://www.cnblogs.com/hellocby/archive/2012/12/20/2826318.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326391548&siteId=291194637