Swift `join` 在连接带有国家/地区标志的字符串时挂起

Swift `join` hangs when joining string with country flag

我在 Swift 1.2 中工作时发现了这一点。我已将其报告为错误。但不知道为什么?

import UIKit

var str = " LHR ✈️ SFO "

([str] as NSArray).componentsJoinedByString("") // Will work
join("", [str]) // Hangs forever

Apple 在 swift 2.0 中有此修复问题,join 被另一种方法 joinWithSeparator(separator: String) -> String 替换,该方法可以很好地处理标志。

这是代码片段。

var str = " LHR ✈️ SFO "

([str] as NSArray).componentsJoinedByString("") // Will work

[str].joinWithSeparator("")

输出

 LHR ✈️ SFO 
 LHR ✈️ SFO 
 LHR ✈️ SFO