OptionSetType

protocol OptionSetType

Supplies convenient conformance to SetAlgebraType for any type whose RawValue is a BitwiseOperationsType. For example:

struct PackagingOptions : OptionSetType {
  let rawValue: Int
  init(rawValue: Int) { self.rawValue = rawValue }

  static let Box = PackagingOptions(rawValue: 1)
  static let Carton = PackagingOptions(rawValue: 2)
  static let Bag = PackagingOptions(rawValue: 4)
  static let Satchel = PackagingOptions(rawValue: 8)
  static let BoxOrBag: PackagingOptions = [Box, Bag]
  static let BoxOrCartonOrBag: PackagingOptions = [Box, Carton, Bag]
}

In the example above, PackagingOptions.Element is the same type as PackagingOptions, and instance a subsumes instance b if and only if a.rawValue & b.rawValue == b.rawValue.

Inheritance ArrayLiteralConvertible, Equatable, RawRepresentable, SetAlgebraType View Protocol Hierarchy →
Associated Types
Element = Self

An OptionSet's Element type is normally Self.

RawValue

The "raw" type that can be used to represent all values of Self.

Every distinct value of self has a corresponding unique value of RawValue, but RawValue may have representations that do not correspond to a value of Self.

Import import Swift

Initializers

init(rawValue:) Required

Convert from a value of RawValue, succeeding unconditionally.

Declaration

init(rawValue: Self.RawValue)

Declared In

OptionSetType , RawRepresentable
init(arrayLiteral:)

Create an instance initialized with elements.

Declaration

init(arrayLiteral elements: Self.Element...)

Declared In

ArrayLiteralConvertible
init() Required

Creates an empty set.

  • Equivalent to [] as Self

Declaration

init()

Declared In

SetAlgebraType
init(_:)

Creates the set containing all elements of sequence.

Declaration

init<S : SequenceType where S.Generator.Element == Element>(_ sequence: S)

Declared In

SetAlgebraType

Instance Variables

var rawValue: Self.RawValue Required

The corresponding value of the "raw" type.

Self(rawValue: self.rawValue)! is equivalent to self.

Declaration

var rawValue: Self.RawValue { get }

Declared In

RawRepresentable
var isEmpty: Bool

Returns true iff self.contains(e) is false for all e.

Declaration

var isEmpty: Bool { get }

Declared In

SetAlgebraType

Static Methods

static func element(_:isDisjointWith:)

Returns true iff a is disjoint with b.

Two elements are disjoint when neither one subsumes the other.

See Also: Self.element(, subsumes:_)

Declaration

static func element(a: Self.Element, isDisjointWith b: Self.Element) -> Bool

Declared In

SetAlgebraType
static func element(_:subsumes:)

Returns true iff a subsumes b.

  • Equivalent to ([a] as Self).isSupersetOf([b])

Declaration

static func element(a: Self.Element, subsumes b: Self.Element) -> Bool

Declared In

SetAlgebraType

Instance Methods

func ==(_:rhs:) Required

Returns true if lhs is equal to rhs.

Equality implies substitutability. When x == y, x and y are interchangeable in any code that only depends on their values.

Class instance identity as distinguished by triple-equals === is notably not part of an instance's value. Exposing other non-value aspects of Equatable types is discouraged, and any that are exposed should be explicitly pointed out in documentation.

Equality is an equivalence relation

  • x == x is true
  • x == y implies y == x
  • x == y and y == z implies x == z

Inequality is the inverse of equality, i.e. !(x == y) iff x != y.

Declaration

func ==(lhs: Self, rhs: Self) -> Bool

Declared In

Equatable
func contains(_:) Required

Returns true if self contains member.

  • Equivalent to self.intersect([member]) == [member]

Declaration

func contains(member: Self.Element) -> Bool

Declared In

SetAlgebraType
func exclusiveOr(_:)

Returns the set of elements contained in self or in other, but not in both self and other.

Declaration

func exclusiveOr(other: Self) -> Self

Declared In

SetAlgebraType
mutating func exclusiveOrInPlace(_:) Required

Replaces self with a set containing all elements contained in either self or other, but not both.

  • Equivalent to replacing self with self.exclusiveOr(other)

Declaration

mutating func exclusiveOrInPlace(other: Self)

Declared In

SetAlgebraType
mutating func insert(_:) Required

If member is not already contained in self, inserts it.

  • Equivalent to self.unionInPlace([member]) Postcondition: self.contains(member)

Declaration

mutating func insert(member: Self.Element)

Declared In

SetAlgebraType
func intersect(_:)

Returns the set of elements contained in both self and other.

Declaration

func intersect(other: Self) -> Self

Declared In

SetAlgebraType
mutating func intersectInPlace(_:) Required

Removes all elements of self that are not also present in other.

  • Equivalent to replacing self with self.intersect(other) Postcondition: self.isSubsetOf(other)

Declaration

mutating func intersectInPlace(other: Self)

Declared In

SetAlgebraType
func isDisjointWith(_:)

Returns true iff self.intersect(other).isEmpty.

Declaration

func isDisjointWith(other: Self) -> Bool

Declared In

SetAlgebraType
func isSubsetOf(_:)

Returns true iff every element of self is contained in other.

Declaration

func isSubsetOf(other: Self) -> Bool

Declared In

SetAlgebraType
func isSupersetOf(_:)

Returns true iff every element of other is contained in self.

Declaration

func isSupersetOf(other: Self) -> Bool

Declared In

SetAlgebraType
mutating func remove(_:) Required

If member is contained in self, removes and returns it. Otherwise, removes all elements subsumed by member and returns nil.

Postcondition: self.intersect([member]).isEmpty

Declaration

mutating func remove(member: Self.Element) -> Self.Element?

Declared In

SetAlgebraType
func subtract(_:)

Returns the set of elements contained in self but not in other.

Declaration

func subtract(other: Self) -> Self

Declared In

SetAlgebraType
mutating func subtractInPlace(_:)

Removes all elements of other from self.

  • Equivalent to replacing self with self.subtract(other).

Declaration

mutating func subtractInPlace(other: Self)

Declared In

SetAlgebraType
func union(_:)

Returns the set of elements contained in self, in other, or in both self and other.

Declaration

func union(other: Self) -> Self

Declared In

SetAlgebraType
mutating func unionInPlace(_:) Required

Insert all elements of other into self.

  • Equivalent to replacing self with self.union(other). Postcondition: self.isSupersetOf(other)

Declaration

mutating func unionInPlace(other: Self)

Declared In

SetAlgebraType

Default Implementations

init(_:)

Creates the set containing all elements of sequence.

Declaration

init<S : SequenceType where S.Generator.Element == Element>(_ sequence: S)

Declared In

SetAlgebraType
init(arrayLiteral:)

Creates a set containing all elements of the given arrayLiteral.

This initializer allows an array literal containing Self.Element to represent an instance of the set, wherever it is implied by the type context.

Declaration

init(arrayLiteral: Self.Element...)

Declared In

SetAlgebraType
var isEmpty: Bool

Returns true iff self.contains(e) is false for all e.

Declaration

var isEmpty: Bool { get }

Declared In

SetAlgebraType
static func element(_:isDisjointWith:)

Returns true iff a is disjoint with b.

Two elements are disjoint when neither one subsumes the other.

See Also: Self.element(, subsumes:_)

Declaration

static func element(a: Self.Element, isDisjointWith b: Self.Element) -> Bool

Declared In

SetAlgebraType
static func element(_:subsumes:)

Returns true iff a subsumes b.

  • Equivalent to ([a] as Self).isSupersetOf([b])

Declaration

static func element(a: Self.Element, subsumes b: Self.Element) -> Bool

Declared In

SetAlgebraType
func exclusiveOr(_:)

Returns the set of elements contained in self or in other, but not in both self and other.

Declaration

func exclusiveOr(other: Self) -> Self
func intersect(_:)

Returns the set of elements contained in both self and other.

Declaration

func intersect(other: Self) -> Self
func isDisjointWith(_:)

Returns true iff self.intersect(other).isEmpty.

Declaration

func isDisjointWith(other: Self) -> Bool

Declared In

SetAlgebraType
func isStrictSubsetOf(_:)

Returns true iff every element of self is contained in other and other contains an element that is not contained in self.

Declaration

func isStrictSubsetOf(other: Self) -> Bool

Declared In

SetAlgebraType
func isStrictSupersetOf(_:)

Returns true iff every element of other is contained in self and self contains an element that is not contained in other.

Declaration

func isStrictSupersetOf(other: Self) -> Bool

Declared In

SetAlgebraType
func isSubsetOf(_:)

Returns true iff every element of self is contained in other.

Declaration

func isSubsetOf(other: Self) -> Bool

Declared In

SetAlgebraType
func isSupersetOf(_:)

Returns true iff every element of other is contained in self.

Declaration

func isSupersetOf(other: Self) -> Bool

Declared In

SetAlgebraType
func subtract(_:)

Returns the set of elements contained in self but not in other.

Declaration

func subtract(other: Self) -> Self

Declared In

SetAlgebraType
mutating func subtractInPlace(_:)

Removes all elements of other from self.

  • Equivalent to replacing self with self.subtract(other).

Declaration

mutating func subtractInPlace(other: Self)

Declared In

SetAlgebraType
func union(_:)

Returns the set of elements contained in self, in other, or in both self and other.

Declaration

func union(other: Self) -> Self

Where Element == Self

func contains(_:)

Returns true if self contains member.

  • Equivalent to self.intersect([member]) == [member]

Declaration

func contains(member: Self) -> Bool
mutating func insert(_:)

If member is not already contained in self, insert it.

  • Equivalent to self.unionInPlace([member]) Postcondition: self.contains(member)

Declaration

mutating func insert(member: Self)
mutating func remove(_:)

If member is contained in self, remove and return it. Otherwise, return nil.

Postcondition: self.intersect([member]).isEmpty

Declaration

mutating func remove(member: Self) -> Self?

Where RawValue : BitwiseOperationsType

init()

Create an empty instance.

  • Equivalent to [] as Self

Declaration

init()
mutating func exclusiveOrInPlace(_:)

Replace self with a set containing all elements contained in either self or other, but not both.

  • Equivalent to replacing self with self.exclusiveOr(other)

Declaration

mutating func exclusiveOrInPlace(other: Self)
mutating func intersectInPlace(_:)

Remove all elements of self that are not also present in other.

  • Equivalent to replacing self with self.intersect(other) Postcondition: self.isSubsetOf(other)

Declaration

mutating func intersectInPlace(other: Self)
mutating func unionInPlace(_:)

Insert all elements of other into self.

  • Equivalent to replacing self with self.union(other). Postcondition: self.isSupersetOf(other)

Declaration

mutating func unionInPlace(other: Self)