表达式过于复杂,无法在合理的时间内解决;考虑将表达式分解为不同的 sub-expressions?
expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions?
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
我在使用“+”运算符连接字符串的标题中遇到上述错误。
有什么方法可以解决这个问题,因为我有一个带有连接字符串的“+”运算符的批量数据。
请帮忙
将你的字符串拆分为一些字符串,然后更改为 Swift 3.0 API
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
在调用NSAttributedString
的init方法之前简单地创建文字串
let string = "Your baby in week three<br>" +
"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!). <br>" +
"<br>" +
"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! <br>" +
"<br>" +
"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 attrStr = try! NSAttributedString(
data: string.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
您可以使用更少耦合且对编译器更友好的表达式
let dataStr: String = [
"Your baby in week three",
"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",
"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!",
"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!"
].joined(separator: "\n")
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
我在使用“+”运算符连接字符串的标题中遇到上述错误。 有什么方法可以解决这个问题,因为我有一个带有连接字符串的“+”运算符的批量数据。 请帮忙
将你的字符串拆分为一些字符串,然后更改为 Swift 3.0 API
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
在调用NSAttributedString
let string = "Your baby in week three<br>" +
"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!). <br>" +
"<br>" +
"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! <br>" +
"<br>" +
"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 attrStr = try! NSAttributedString(
data: string.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
您可以使用更少耦合且对编译器更友好的表达式
let dataStr: String = [
"Your baby in week three",
"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",
"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!",
"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!"
].joined(separator: "\n")