gpt4 book ai didi

swift - 将 U+20000 或以上的 UnicodeScalar 附加到 String

转载 作者:可可西里 更新时间:2023-11-01 02:27:02 24 4
gpt4 key购买 nike

为什么我不能将 U+20000 或以上的 UnicodeScalar 附加到 String

var str = ""
let bmpScalar = UnicodeScalar(0x04e19) // 丙
let smpScalar = UnicodeScalar(0x1F600) // 😀
let sipScalar = UnicodeScalar(0x20011) // 𠀑

str.append(bmpScalar) // "丙"
str.append(smpScalar) // "丙😀"
str.append(sipScalar) // < [!] Exection was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).

它可以编译,但会导致运行时错误:EXC_BAD_INSTRUCTION

虽然以下所有工作:

str.extend(String(sipScalar))
str += String(sipScalar)
str.append(Character(sipScalar))
sipScalar.writeTo(&str)

最佳答案

此问题已在版本 6.3 (6D520o) 中修复

关于swift - 将 U+20000 或以上的 UnicodeScalar 附加到 String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27312706/

24 4 0