insert
Declaration
@discardableResult mutating func insert(_ newMember: Self.Element) -> (inserted: Bool, memberAfterInsert: Self.Element)
Summary
Returns
(true, newMember) if newMember was not contained in
self. Otherwise, returns (false, oldMember), where oldMember is
the member of the set equal to newMember.
Parameters
| Name | Type | Summary |
|---|---|---|
| newMember | Self.Element | The element to insert. |
Adds the given element to the option set if it is not already a member.
In the following example, the
.secondDayshipping option is added tothe
freeOptionsoption set ifpurchasePriceis greater than 50.0. Forthe
ShippingOptionsdeclaration, see theOptionSetprotocoldiscussion.
let purchasePrice = 87.55
var freeOptions: ShippingOptions = [.standard, .priority]
if purchasePrice > 50 {
freeOptions.insert(.secondDay)
}
print(freeOptions.contains(.secondDay))
// Prints "true"