範囲内のランダムな絵文字を取得したいと思います。インデックスから値を取得
let emojiRanges = [
0x1F601...0x1F64F,
0x1F680...0x1F6C0,
]
let flattenEmoji = emojiRanges.flatten()
// the loop for emoji works
for i in flattenEmoji {
let st = String(format:"0x%2X %@", i, String(UnicodeScalar(i)))
print(st)
}
// but this is not possible to obtain value at wanted index
//there is a compiler error:
let randomSign = String(UnicodeScalar(flattenEmoji[arc4random_uniform(UInt32(flattenEmoji.count))]))
print("RANDOM \(randomSign)")
エラー:
ViewController.swift:68:67: Cannot subscript a value of type 'FlattenBidirectionalCollection<[Range]>' (aka 'FlattenBidirectionalCollection>>') with an index of type 'UInt32'
結果を得るための適切な方法は何ですか?