"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
}
}