appendAttributedString return 类型为 Void 的值
appendAttributedString return value of type Void
我正在尝试附加两个 NSAttributedString
。
let string_1 : NSAttributedString = self.answerTextView.attributedText
let string_2 : NSAttributedString = handleHtml(i) // a function that returns a NSAttributedString
let finalStr : NSAttributedString = string_1.mutableCopy().appendAttributedString(string_2)
但是我在第三行出错了:
Cannot convert value of type 'Void' (aka '()') to specified type 'NSAttributedString'
我该如何解决这个问题?谢谢
appendAttributedString
更新调用者。它不是 return 新字符串。尝试以下操作:
let string_1 : NSAttributedString = self.answerTextView.attributedText
let string_2 : NSAttributedString = handleHtml(i) // a function that returns a NSAttributedString
let tmpStr : NSMutableAttributedString = string_1.mutableCopy()
tmpStr.appendAttributedString(string_2)
let finalStr : NSAttributedString = tmpStr.copy()
定义如下:
//MARK: Custom functions
func getQueueAttributedString(number N: Int) -> NSAttributedString? {
let uploadSymbolAttributes = [NSForegroundColorAttributeName: UEColor.brown.six, NSFontAttributeName: UEFont.unearthCharacterFont(13)]
let attributedString = NSMutableAttributedString(string: UEFontCharacter.triangle_up, attributes: uploadSymbolAttributes)
let queueAttributes = [NSForegroundColorAttributeName: UEColor.brown.six, NSFontAttributeName: UEFont.museo300(withSize: 13)]
let queueString = NSAttributedString(string: " \(N) items queued", attributes: queueAttributes)
attributedString.append(queueString)
return attributedString
}
其中 UEFont
是自定义 UIFont
,UEColor
是自定义 UIColor
的静态结构,UEFontCharacter
是线性图标字体。
我正在尝试附加两个 NSAttributedString
。
let string_1 : NSAttributedString = self.answerTextView.attributedText
let string_2 : NSAttributedString = handleHtml(i) // a function that returns a NSAttributedString
let finalStr : NSAttributedString = string_1.mutableCopy().appendAttributedString(string_2)
但是我在第三行出错了:
Cannot convert value of type 'Void' (aka '()') to specified type 'NSAttributedString'
我该如何解决这个问题?谢谢
appendAttributedString
更新调用者。它不是 return 新字符串。尝试以下操作:
let string_1 : NSAttributedString = self.answerTextView.attributedText
let string_2 : NSAttributedString = handleHtml(i) // a function that returns a NSAttributedString
let tmpStr : NSMutableAttributedString = string_1.mutableCopy()
tmpStr.appendAttributedString(string_2)
let finalStr : NSAttributedString = tmpStr.copy()
定义如下:
//MARK: Custom functions
func getQueueAttributedString(number N: Int) -> NSAttributedString? {
let uploadSymbolAttributes = [NSForegroundColorAttributeName: UEColor.brown.six, NSFontAttributeName: UEFont.unearthCharacterFont(13)]
let attributedString = NSMutableAttributedString(string: UEFontCharacter.triangle_up, attributes: uploadSymbolAttributes)
let queueAttributes = [NSForegroundColorAttributeName: UEColor.brown.six, NSFontAttributeName: UEFont.museo300(withSize: 13)]
let queueString = NSAttributedString(string: " \(N) items queued", attributes: queueAttributes)
attributedString.append(queueString)
return attributedString
}
其中 UEFont
是自定义 UIFont
,UEColor
是自定义 UIColor
的静态结构,UEFontCharacter
是线性图标字体。