appendAttributedString返回Void类型的值

时间:2015-09-16 17:50:30

标签: ios swift nsattributedstring

我正在尝试附加两个.then

console.log(1);
getJSON('http://localhost/myproject/data.json').then(function(response){
    console.log(response);
    return;
});
console.log(3);

但我在第三行遇到错误:

  

无法转换类型' Void' (又名'()')指定类型' NSAttributedString'

我该如何解决这个问题?感谢

2 个答案:

答案 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是自定义UIFontUEColor是自定义UIColor的静态结构,UEFontCharacter是线性图标字体。