我正在尝试附加两个.then
。
console.log(1);
getJSON('http://localhost/myproject/data.json').then(function(response){
console.log(response);
return;
});
console.log(3);
但我在第三行遇到错误:
无法转换类型' Void' (又名'()')指定类型' NSAttributedString'
我该如何解决这个问题?感谢
答案 0 :(得分:9)
appendAttributedString
更新来电者。它不会返回新字符串。请尝试以下方法:
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()
答案 1 :(得分:0)
这样的东西:
//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
是线性图标字体。