Swift-检查属性文本是否为空
我有一个UITextField,在该字段上我将当前值设置为属性文本,如下所示:Swift-检查属性文本是否为空,swift,string,nsattributedstring,nsmutableattributedstring,Swift,String,Nsattributedstring,Nsmutableattributedstring,我有一个UITextField,在该字段上我将当前值设置为属性文本,如下所示: public var currentValue: NSAttributedString { get { return inputField.attributedText ?? NSAttributedString() } set { inputField.attributedText = newValue } } 这以前只是一个字符串,但现在我需要为文
public var currentValue: NSAttributedString {
get {
return inputField.attributedText ?? NSAttributedString()
}
set {
inputField.attributedText = newValue
}
}
这以前只是一个字符串,但现在我需要为文本的某些部分添加格式
但是,我有一个方法需要传递这些字段,该方法从条件开始,以查看字段是否为空。在此之前,我从以下内容开始:
if textField.currentValue.isEmpty {
// Perform logic
}
然而,NSAttributedText显然没有isEmpty成员。如何对NSAttributedText执行相同的检查?
NSAttributedText
没有isEmpty
属性,但它有一个调用的属性。您只需检查它是否等于零:
if currentValue.length == .zero {
// Perform logic
}
NSAttributedText
没有isEmpty
属性,但它有一个被调用的属性。您只需检查它是否等于零:
if currentValue.length == .zero {
// Perform logic
}