Instance Method

remove(_:)

Removes the given element and all elements subsumed by it.

Declaration

@discardableResult mutating func remove(_ member: AnchoringComponent.Target.Alignment) -> AnchoringComponent.Target.Alignment?

Parameters

member

The element of the set to remove.

Return Value

The intersection of [member] and the set, if the intersection was nonempty; otherwise, nil.

Discussion

In the following example, the .priority shipping option is removed from the options option set. Attempting to remove the same shipping option a second time results in nil, because options no longer contains .priority as a member.

var options: ShippingOptions = [.secondDay, .priority]
let priorityOption = options.remove(.priority)
print(priorityOption == .priority)
// Prints "true"

print(options.remove(.priority))
// Prints "nil"

In the next example, the .express element is passed to remove(_:). Although .express is not a member of options, .express subsumes the remaining .secondDay element of the option set. Therefore, options is emptied and the intersection between .express and options is returned.

let expressOption = options.remove(.express)
print(expressOption == .express)
// Prints "false"
print(expressOption == .secondDay)
// Prints "true"

See Also

Option Set Conformance

var isEmpty: Bool

A Boolean value that indicates whether the set has no elements.

func contains(AnchoringComponent.Target.Alignment) -> Bool

Returns a Boolean value that indicates whether a given element is a member of the option set.

func formIntersection(AnchoringComponent.Target.Alignment)

Removes all elements of this option set that are not also present in the given set.

func formSymmetricDifference(AnchoringComponent.Target.Alignment)

Replaces this set with a new set containing all elements contained in either this set or the given set, but not in both.

func formUnion(AnchoringComponent.Target.Alignment)

Inserts the elements of another set into this option set.

func intersection(AnchoringComponent.Target.Alignment) -> AnchoringComponent.Target.Alignment

Returns a new option set with only the elements contained in both this set and the given set.

func isDisjoint(with: AnchoringComponent.Target.Alignment) -> Bool

Returns a Boolean value that indicates whether the set has no members in common with the given set.

func isStrictSubset(of: AnchoringComponent.Target.Alignment) -> Bool

Returns a Boolean value that indicates whether this set is a strict subset of the given set.

func isStrictSuperset(of: AnchoringComponent.Target.Alignment) -> Bool

Returns a Boolean value that indicates whether this set is a strict superset of the given set.

func isSubset(of: AnchoringComponent.Target.Alignment) -> Bool

Returns a Boolean value that indicates whether the set is a subset of another set.

func isSuperset(of: AnchoringComponent.Target.Alignment) -> Bool

Returns a Boolean value that indicates whether the set is a superset of the given set.

func subtract(AnchoringComponent.Target.Alignment)

Removes the elements of the given set from this set.

func subtracting(AnchoringComponent.Target.Alignment) -> AnchoringComponent.Target.Alignment

Returns a new set containing the elements of this set that do not occur in the given set.

func symmetricDifference(AnchoringComponent.Target.Alignment) -> AnchoringComponent.Target.Alignment

Returns a new option set with the elements contained in this set or in the given set, but not in both.

func union(AnchoringComponent.Target.Alignment) -> AnchoringComponent.Target.Alignment

Returns a new option set of the elements contained in this set, in the given set, or in both.