Instance Methodswift 6.0.3Swift

take

Takes the wrapped value being stored in this instance and returns it while also setting the instance to nil. If there is no value being stored in this instance, this returns nil instead.

mutating func take() -> Optional<Wrapped>

Returns

The wrapped value being stored in this instance. If this instance is nil, returns nil.

var numberOfShoes: Int? = 34

if let numberOfShoes = numberOfShoes.take() {
  print(numberOfShoes)
  // Prints "34"
}

print(numberOfShoes)
// Prints "nil"