Instance Methodswift 6.0.1Swift
formIntersection(_:)
Removes the elements of the set that aren’t also in the given sequence.
mutating func formIntersection<S>(_ other: S) where Element == S.Element, S : Sequence
Parameters
- other
A sequence of elements.
other
must be finite.
In the following example, the elements of the employees
set that are not also members of the neighbors
set are removed. In particular, the names "Alicia"
, "Chris"
, and "Diana"
are removed.
var employees: Set = ["Alicia", "Bethany", "Chris", "Diana", "Eric"]
let neighbors = ["Bethany", "Eric", "Forlani", "Greta"]
employees.formIntersection(neighbors)
print(employees)
// Prints "["Bethany", "Eric"]"
Other members in extension
Types
struct Index
The position of an element in a set.
struct Iterator
An iterator over the members of a
Set<Element>
.
Type members
init(
) Creates an empty set.
init<Source>(Source
) Creates a new set from a finite sequence of items.
init(arrayLiteral: Element...
) Creates a set containing the elements of the given array literal.
static func == (lhs: Set<Element>, rhs: Set<Element>
) -> Bool Returns a Boolean value indicating whether two sets have equal elements.
Instance members
var capacity: Int
The total number of elements that the set can contain without allocating new storage.
var count: Int
The number of elements in the set.
var customMirror: Mirror
A mirror that reflects the set.
var debugDescription: String
A string that represents the contents of the set, suitable for debugging.
var description: String
A string that represents the contents of the set.
var endIndex: Set<Element>.Index
The “past the end” position for the set—that is, the position one greater than the last valid subscript argument.
var isEmpty: Bool
A Boolean value that indicates whether the set is empty.
var startIndex: Set<Element>.Index
The starting position for iterating members of the set.
subscript(Set<Element>.Index
) -> Element Accesses the member at the given position.
func contains(Element
) -> Bool Returns a Boolean value that indicates whether the given element exists in the set.
func filter((Element) throws -> Bool
) rethrows -> Set<Element> Returns a new set containing the elements of the set that satisfy the given predicate.
func firstIndex(of: Element
) -> Set<Element>.Index? Returns the index of the given element in the set, or
nil
if the element is not a member of the set.func formIndex(after: inout Set<Element>.Index
) func formSymmetricDifference(Set<Element>
) Removes the elements of the set that are also in the given sequence and adds the members of the sequence that are not already in the set.
func formSymmetricDifference<S>(S
) Replace this set with the elements contained in this set or the given set, but not both.
func formUnion<S>(S
) Inserts the elements of the given sequence into the set.
func hash(into: inout Hasher
) Hashes the essential components of this value by feeding them into the given hasher.
func index(after: Set<Element>.Index
) -> Set<Element>.Index func insert(Element
) -> (inserted: Bool, memberAfterInsert: Element) Inserts the given element in the set if it is not already present.
func intersection(Set<Element>
) -> Set<Element> Returns a new set with the elements that are common to both this set and the given sequence.
func intersection<S>(S
) -> Set<Element> Returns a new set with the elements that are common to both this set and the given sequence.
func isDisjoint(with: Set<Element>
) -> Bool Returns a Boolean value that indicates whether this set has no members in common with the given set.
func isDisjoint<S>(with: S
) -> Bool Returns a Boolean value that indicates whether the set has no members in common with the given sequence.
func isStrictSubset(of: Set<Element>
) -> Bool Returns a Boolean value that indicates whether the set is a strict subset of the given sequence.
func isStrictSubset<S>(of: S
) -> Bool Returns a Boolean value that indicates whether the set is a strict subset of the given sequence.
func isStrictSuperset(of: Set<Element>
) -> Bool Returns a Boolean value that indicates whether the set is a strict superset of the given sequence.
func isStrictSuperset<S>(of: S
) -> Bool Returns a Boolean value that indicates whether the set is a strict superset of the given sequence.
func isSubset(of: Set<Element>
) -> Bool Returns a Boolean value that indicates whether this set is a subset of the given set.
func isSubset<S>(of: S
) -> Bool Returns a Boolean value that indicates whether the set is a subset of the given sequence.
func isSuperset(of: Set<Element>
) -> Bool Returns a Boolean value that indicates whether this set is a superset of the given set.
func isSuperset<S>(of: S
) -> Bool Returns a Boolean value that indicates whether the set is a superset of the given sequence.
func makeIterator(
) -> Set<Element>.Iterator Returns an iterator over the members of the set.
func popFirst(
) -> Element? Removes and returns the first element of the set.
func remove(Element
) -> Element? Removes the specified element from the set.
func remove(at: Set<Element>.Index
) -> Element Removes the element at the given index of the set.
func removeAll(keepingCapacity: Bool
) Removes all members from the set.
func removeFirst(
) -> Element Removes the first element of the set.
func reserveCapacity(Int
) Reserves enough space to store the specified number of elements.
func subtract(Set<Element>
) Removes the elements of the given set from this set.
func subtract<S>(S
) Removes the elements of the given sequence from the set.
func subtracting(Set<Element>
) -> Set<Element> Returns a new set containing the elements of this set that do not occur in the given set.
func subtracting<S>(S
) -> Set<Element> Returns a new set containing the elements of this set that do not occur in the given sequence.
func symmetricDifference<S>(S
) -> Set<Element> Returns a new set with the elements that are either in this set or in the given sequence, but not in both.
func union<S>(S
) -> Set<Element> Returns a new set with the elements of both this set and the given sequence.
func update(with: Element
) -> Element? Inserts the given element into the set unconditionally.