Ios 表达式过于复杂,无法在合理的时间内解决;考虑把表达式分解成不同的子表达式吗? 让attrStr=try!NSAttribute字符串( 数据:“您的宝宝在第三周\n”+ “怀孕三周后,你可能会想知道这个小奇迹是怎么发生的(就像在《科学》杂志上,我们假设你知道另一部分!)。\n”+ “\n”+ “因此,这里是这样的:在受孕时,你伴侣的精子和你的卵子结合在一起,形成了一个细胞球(或者一个胚泡,如果你想获得真正的技术性的话)它现在开始了从输卵管到子宫的6天旅程,在那里它将附着在您的子宫内膜上,在9个月后,将在您的怀里产生一个真正的活婴儿!\n“+ “\n”+ “令人惊讶的是,虽然你在几个月内(或直到出生之前)都不会知道您宝宝的性别已经确定。受精卵包含46条染色体,其中23条来自您,23条来自父亲。您作为母亲将始终提供X染色体,但父亲可以提供X或Y染色体。XX和您将有一个女孩,XY和您将在9个月后有一个小男孩!”。数据使用编码(NSULOSSYCONVERSION编码,allowLossyConversion:true)!, 选项:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType], 文件属性:无) trimestercontent.attributedText=attrStr

Ios 表达式过于复杂,无法在合理的时间内解决;考虑把表达式分解成不同的子表达式吗? 让attrStr=try!NSAttribute字符串( 数据:“您的宝宝在第三周\n”+ “怀孕三周后,你可能会想知道这个小奇迹是怎么发生的(就像在《科学》杂志上,我们假设你知道另一部分!)。\n”+ “\n”+ “因此,这里是这样的:在受孕时,你伴侣的精子和你的卵子结合在一起,形成了一个细胞球(或者一个胚泡,如果你想获得真正的技术性的话)它现在开始了从输卵管到子宫的6天旅程,在那里它将附着在您的子宫内膜上,在9个月后,将在您的怀里产生一个真正的活婴儿!\n“+ “\n”+ “令人惊讶的是,虽然你在几个月内(或直到出生之前)都不会知道您宝宝的性别已经确定。受精卵包含46条染色体,其中23条来自您,23条来自父亲。您作为母亲将始终提供X染色体,但父亲可以提供X或Y染色体。XX和您将有一个女孩,XY和您将在9个月后有一个小男孩!”。数据使用编码(NSULOSSYCONVERSION编码,allowLossyConversion:true)!, 选项:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType], 文件属性:无) trimestercontent.attributedText=attrStr,ios,iphone,swift,swift2,Ios,Iphone,Swift,Swift2,使用“+”运算符连接字符串时,标题中出现上述错误。 有没有什么方法可以解决这个问题,因为我有一个带有“+”操作符的批量数据,可以连接字符串。 请帮助将字符串拆分为一些字符串,并更改为Swift 3.0 API let attrStr = try! NSAttributedString( data: "Your baby in week three\n" + "Three weeks into your pregnancy, and you migh

使用“+”运算符连接字符串时,标题中出现上述错误。 有没有什么方法可以解决这个问题,因为我有一个带有“+”操作符的批量数据,可以连接字符串。
请帮助

将字符串拆分为一些字符串,并更改为Swift 3.0 API

    let attrStr = try! NSAttributedString(
        data: "Your baby in week three\n" +
            "Three weeks into your pregnancy, and you might be wondering just how this little miracle occurred (as in the science bit we will assume you know the other part!). \n" +
            "\n" +
            "So here goes: the joining of your partner's sperm and your egg at the moment of conception resulted in a ball of cells (or a blastocyst, if you want to get really technical) which is now starting the 6 day journey from the fallopian tube to the uterus where it will attach itself to the lining of your womb and in nine months time, will result in a real live baby in your arms! \n" +
            "\n" +
            "Amazingly, although you will not know for a few months (or until the birth) the <b><font color=#00690c >sex of your baby</font></b> has already been determined. The fertilised egg contains <b><font color=#e3007b>46</font></b> chromosomes with <b><font color=#e3007b>23</font></b> from you and <b><font color=#e3007b>23</font></b> from the dad. You as mum will always provide the <b><font color=#e3007b>X</font></b> chromosome but the dad can provide an <b><font color=#e3007b>X</font></b> or <b><font color=#e3007b>Y</font></b> chromosome. <b><font color=#e3007b>XX</font></b> and you will be having a girl, <b><font color=#e3007b>XY</font></b> and you will have a little boy in 9 months time!".dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
        options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
        documentAttributes: nil)
    trimestercontent.attributedText = attrStr
让a=“你的宝宝在怀孕三周后的第三周\n个星期内出生,你可能会想知道这个小奇迹是怎么发生的(在科学部分,我们假设你知道另一部分!)。\n\n”
let b=“因此,这里是这样的:在受孕时,你伴侣的精子和你的卵子结合在一起,形成了一个细胞球(或者一个胚泡,如果你想获得真正的技术性知识的话)它现在开始了从输卵管到子宫的6天旅程,在那里它将附着在您的子宫内膜上,在9个月后,将在您的怀里产生一个真正的活婴儿!\n“+
“\n”
让c=“令人惊讶的是,尽管您在几个月内(或在出生前)都不会知道您的婴儿性别已经确定。受精卵包含46条染色体,其中23条来自您,23条来自父亲。您作为母亲将始终提供X染色体,但父亲可以提供X或Y染色体。XX和您将有一个女孩,XY和您将在9个月后有一个小男孩!”
设d=a+b+c
让attrStr=try!NSAttributedString.init(数据:d.data(使用:String.Encoding.unicode,allowossyconversion:true)!,选项:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType],DocumentAttribute:nil)
trimestercontent.attributedText=attrStr

将字符串拆分为一些字符串,并更改为Swift 3.0 API

    let attrStr = try! NSAttributedString(
        data: "Your baby in week three\n" +
            "Three weeks into your pregnancy, and you might be wondering just how this little miracle occurred (as in the science bit we will assume you know the other part!). \n" +
            "\n" +
            "So here goes: the joining of your partner's sperm and your egg at the moment of conception resulted in a ball of cells (or a blastocyst, if you want to get really technical) which is now starting the 6 day journey from the fallopian tube to the uterus where it will attach itself to the lining of your womb and in nine months time, will result in a real live baby in your arms! \n" +
            "\n" +
            "Amazingly, although you will not know for a few months (or until the birth) the <b><font color=#00690c >sex of your baby</font></b> has already been determined. The fertilised egg contains <b><font color=#e3007b>46</font></b> chromosomes with <b><font color=#e3007b>23</font></b> from you and <b><font color=#e3007b>23</font></b> from the dad. You as mum will always provide the <b><font color=#e3007b>X</font></b> chromosome but the dad can provide an <b><font color=#e3007b>X</font></b> or <b><font color=#e3007b>Y</font></b> chromosome. <b><font color=#e3007b>XX</font></b> and you will be having a girl, <b><font color=#e3007b>XY</font></b> and you will have a little boy in 9 months time!".dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
        options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
        documentAttributes: nil)
    trimestercontent.attributedText = attrStr
让a=“你的宝宝在怀孕三周后的第三周\n个星期内出生,你可能会想知道这个小奇迹是怎么发生的(在科学部分,我们假设你知道另一部分!)。\n\n”
let b=“因此,这里是这样的:在受孕时,你伴侣的精子和你的卵子结合在一起,形成了一个细胞球(或者一个胚泡,如果你想获得真正的技术性知识的话)它现在开始了从输卵管到子宫的6天旅程,在那里它将附着在您的子宫内膜上,在9个月后,将在您的怀里产生一个真正的活婴儿!\n“+
“\n”
让c=“令人惊讶的是,尽管您在几个月内(或在出生前)都不会知道您的婴儿性别已经确定。受精卵包含46条染色体,其中23条来自您,23条来自父亲。您作为母亲将始终提供X染色体,但父亲可以提供X或Y染色体。XX和您将有一个女孩,XY和您将在9个月后有一个小男孩!”
设d=a+b+c
让attrStr=try!NSAttributedString.init(数据:d.data(使用:String.Encoding.unicode,allowossyconversion:true)!,选项:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType],DocumentAttribute:nil)
trimestercontent.attributedText=attrStr

在调用
nsattributestring的init方法之前,只需创建文本字符串

    let a = "Your baby in week three\nThree weeks into your pregnancy, and you might be wondering just how this little miracle occurred (as in the science bit we will assume you know the other part!). \n\n"
    let b = "So here goes: the joining of your partner's sperm and your egg at the moment of conception resulted in a ball of cells (or a blastocyst, if you want to get really technical) which is now starting the 6 day journey from the fallopian tube to the uterus where it will attach itself to the lining of your womb and in nine months time, will result in a real live baby in your arms! \n" +
    "\n"
    let c = "Amazingly, although you will not know for a few months (or until the birth) the <b><font color=#00690c >sex of your baby</font></b> has already been determined. The fertilised egg contains <b><font color=#e3007b>46</font></b> chromosomes with <b><font color=#e3007b>23</font></b> from you and <b><font color=#e3007b>23</font></b> from the dad. You as mum will always provide the <b><font color=#e3007b>X</font></b> chromosome but the dad can provide an <b><font color=#e3007b>X</font></b> or <b><font color=#e3007b>Y</font></b> chromosome. <b><font color=#e3007b>XX</font></b> and you will be having a girl, <b><font color=#e3007b>XY</font></b> and you will have a little boy in 9 months time!"
    let d = a+b+c

    let attrStr = try! NSAttributedString.init(data: d.data(using: String.Encoding.unicode, allowLossyConversion:true)!, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)

    trimestercontent.attributedText = attrStr
让string=“你的宝宝在第三周出生
”+ “怀孕三周后,你可能会想知道这个小奇迹是怎么发生的(就像在《科学》杂志上,我们假设你知道另一部分!)。
”+ “
”+ “因此,这里是这样的:在受孕时,你伴侣的精子和你的卵子结合在一起,形成了一个细胞球(或者一个胚泡,如果你想获得真正的技术性的话)它现在开始了从输卵管到子宫的6天旅程,在那里它将附着在你的子宫内膜上,在9个月的时间里,它将在你的怀抱中产生一个真正的活婴儿+ “
”+ “令人惊讶的是,虽然你在几个月内(或直到出生之前)都不会知道您的婴儿性别已经确定。受精卵包含46条染色体,其中23条来自您,23条来自父亲。您作为母亲将始终提供X染色体,但父亲可以提供X或Y染色体。XX和您将有一个女孩,XY和您将在9个月后有一个小男孩!” 让attrStr=try!nsattributestring( 数据:string.dataUsingEncoding(nsunicoding,allowLossyConversion:true)!, 选项:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType],DocumentAttribute:nil)
在调用
nsattributestring的init方法之前,只需创建文本字符串

    let a = "Your baby in week three\nThree weeks into your pregnancy, and you might be wondering just how this little miracle occurred (as in the science bit we will assume you know the other part!). \n\n"
    let b = "So here goes: the joining of your partner's sperm and your egg at the moment of conception resulted in a ball of cells (or a blastocyst, if you want to get really technical) which is now starting the 6 day journey from the fallopian tube to the uterus where it will attach itself to the lining of your womb and in nine months time, will result in a real live baby in your arms! \n" +
    "\n"
    let c = "Amazingly, although you will not know for a few months (or until the birth) the <b><font color=#00690c >sex of your baby</font></b> has already been determined. The fertilised egg contains <b><font color=#e3007b>46</font></b> chromosomes with <b><font color=#e3007b>23</font></b> from you and <b><font color=#e3007b>23</font></b> from the dad. You as mum will always provide the <b><font color=#e3007b>X</font></b> chromosome but the dad can provide an <b><font color=#e3007b>X</font></b> or <b><font color=#e3007b>Y</font></b> chromosome. <b><font color=#e3007b>XX</font></b> and you will be having a girl, <b><font color=#e3007b>XY</font></b> and you will have a little boy in 9 months time!"
    let d = a+b+c

    let attrStr = try! NSAttributedString.init(data: d.data(using: String.Encoding.unicode, allowLossyConversion:true)!, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)

    trimestercontent.attributedText = attrStr
让string=“你的宝宝在第三周出生
”+ “怀孕三周后