The elements to use as members of the new set. 新しい集合の要素として使うための要素。
Generic Initializer
init(_:)
Creates a new set from a finite sequence of items.
いくつかの要素からなる有限のシーケンスから集合を作成します。
Availability
- iOS 8.0+
- iPadOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 10.2+
Technology
- Swift Standard Library Swift標準ライブラリ
Declaration 宣言
Parameters パラメータ
sequence
Discussion 解説
Use this initializer to create a new set from an existing sequence, for example, an array or a range. このイニシャライザを使って、新しい集合を既存のシーケンス、例えば、配列またはある範囲から作成してください。
let validIndices = Set(0..<7).subtracting([2, 4, 5])
print(validIndices)
// Prints "[6, 0, 1, 3]"
This initializer can also be used to restore set methods after performing sequence operations such as filter(_:)
or map(_:)
on a set. For example, after filtering a set of prime numbers to remove any below 10, you can create a new set by using this initializer.
このイニシャライザはまた、シーケンス演算、例えばfilter(_:)
やmap(_:)
などをある集合上で実行した後で集合に戻す手法として使われることができます。例えば、ひとそろいの素数をフィルタして10の前のどんなものも削除した後で、あなたは新しい集合をこのイニシャライザを使って作成できます。
let primes: Set = [2, 3, 5, 7, 11, 13, 17, 19, 23]
let laterPrimes = Set(primes.lazy.filter { $0 > 10 })
print(laterPrimes)
// Prints "[17, 19, 23, 11, 13]"
Relationships 関係
From Protocol 由来プロトコル
See Also 参照
Creating a Set 集合の作成
init()
Creates an empty set.
空の集合を作成します。
init(minimumCapacity : Int)
Creates an empty set with preallocated space for at least the specified number of elements.
空の集合を、あらかじめアロケートされたスペースで少なくとも指定された要素数に対して作成します。
init<S>(S)
Creates a new set from a finite sequence of items.
いくつかの要素からなる有限のシーケンスから集合を作成します。