Swift 中判断字符串中的字符是否为单词字符的最简单方法是什么?

What is the easiest way in Swift to tell if a character in a String is a word character?

在 Ruby 中,正则表达式允许它像这样简单地完成:

x = "f"
if /^\w$/.match?(x)
    puts "yes"
else
    puts "no"
end

在 Swift 中执行此操作的最简单方法是什么?

您可以使用 Swift Character 属性 isLetter:

let x: Character = "f"
if x.isLetter {
    print("yes")
} else {
    print("no")
}