Instance Method インスタンスメソッド

insert(_:)

Adds the given element to the option set if it is not already a member. 与えられた要素を、それがすでにメンバでないならばオプションセットに加えます。

Declaration 宣言

@discardableResult mutating func insert(_ newMember: AttributedString.FormattingOptions) -> (inserted: Bool, memberAfterInsert: AttributedString.FormattingOptions)

Parameters パラメータ

newMember

The element to insert. 挿入される要素。

Return Value 戻り値

(true, newMember) if newMember was not contained in self. Otherwise, returns (false, oldMember), where oldMember is the member of the set equal to newMember. (true, newMember)、もしnewMemberselfに含まれなかったならば。そうでなければ、(false, oldMember)を返します、そこでoldMembernewMemberに等しいこの集合のメンバです。

Discussion 議論

In the following example, the .secondDay shipping option is added to the freeOptions option set if purchasePrice is greater than 50.0. For the ShippingOptions declaration, see the OptionSet protocol discussion. 次の例において、.secondDay出荷オプションは、purchasePriceが50.0より大きいならば、freeOptionsオプションセットを加えられます。ShippingOptions宣言については、OptionSetプロトコル解説を見てください。


let purchasePrice = 87.55


var freeOptions: ShippingOptions = [.standard, .priority]
if purchasePrice > 50 {
    freeOptions.insert(.secondDay)
}
print(freeOptions.contains(.secondDay))
// Prints "true"

See Also 参照

Performing Set Operations 集合演算を実行する