Discussion 解説
When working with a mirror that reflects a bidirectional or random access collection, you may find it useful to “upgrade” instances of this type to Any
or Any
. For example, to display the last twenty children of a mirror if they can be accessed efficiently, you write the following code:
双方向性のまたはランダムなアクセスのコレクションをリフレクとするミラーを扱う場合、あなたはこの型のインスタンスをAny
またはAny
に「アップグレード」することが役立つのを発見するかもしれません。例えば、あるミラーの最後の20個の子を表示するにはそれらが効率的にアクセスされるならば、あなたは以下のコードを書きます:
if let b = AnyBidirectionalCollection(someMirror.children) {
for element in b.suffix(20) {
print(element)
}
}