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

标签 swift unicode

为什么我不能将 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/

相关文章:

swift - 从 AVAudioPlayer 设置 MPNowPlayingInfoCenter currentTime 和 SongLength

ios - 如何使用 getData() 在 Swift 中使用 ObjC PNChart 库绘制折线图?

java - 检测字符串中的 IRC 颜色

c - Linux 上的 vsnwprintf 替代方案

Go rune literal for high positioned emojis

ios - 核心数据,每次使用相同的登录电子邮件地址和密码登录时,userID 都会取另一个值?

objective-c - 自动将 XIB 文件调整为屏幕大小

ios - 检查一个数组是否包含 Swift 中另一个数组的所有元素

python - 测试终端是否支持伪图形

python - 要列出的 Unicode 字符串