True whether a character is an empty string

"XXX".isEmpty --推荐
"XXX".count == 0 --不推荐,需要遍历,浪费资源

isEmpty situation can not be judged:
"" .isEmpty // false

The solution:
the String plus an extended attribute is calculated:

extension String {
    var isBlank:Bool {
        let trimmedStr = self.trimmingCharacters(in: .whitespacesAndNewlines)
        return trimmedStr.isEmpty
    }
}
Released six original articles · won praise 8 · views 305

Guess you like

Origin blog.csdn.net/qq_44864362/article/details/104095914