---
title: "init(_:)"
framework: swift
role: symbol
role_heading: Initializer
path: "swift/set/init(_:)"
---

# init(_:)

Creates a new set from a finite sequence of items.

## Declaration

```swift
init<Source>(_ sequence: Source) where Element == Source.Element, Source : Sequence
```

## Parameters

- `sequence`: The elements to use as members of the new set.

## Discussion

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. 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]"

## See Also

### Creating a Set

- [init()](swift/set/init().md)
- [init(minimumCapacity:)](swift/set/init(minimumcapacity:).md)
- [init(_:)](swift/set/init(_:)-9cgks.md)
