实例方法
symmetric
symmetricDifference(_:)
返回一个新集合,其中的元素或者在此集合中,或者在给定序列中,但不在两者中。
声明
func symmetricDifference<S>(_ other: S) -> Set<Element> where Element == S.Element, S : Sequence
当
Element
符合 Hashable
时可用。返回值
一套新的。
参数
other
一系列元素。
other
必须是有限的。
详述
在以下示例中,eitherNeighborsOrEmployees
集由 employees
和 neighbors
集的元素组成,它们不在 employees
and
neighbors
中。特别是,名称 "Bethany"
和 "Eric"
不会出现在 eitherNeighborsOrEmployees
中。
let employees: Set = ["Alicia", "Bethany", "Diana", "Eric"]
let neighbors = ["Bethany", "Eric", "Forlani"]
let eitherNeighborsOrEmployees = employees.symmetricDifference(neighbors)
print(eitherNeighborsOrEmployees)
// Prints "["Diana", "Forlani", "Alicia"]"
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift Set subtracting(_:)用法及代码示例
- Swift Set subscript(_:)用法及代码示例
- Swift Set shuffled()用法及代码示例
- Swift Set suffix(from:)用法及代码示例
- Swift Set split(maxSplits:omittingEmptySubsequences:whereSeparator:)用法及代码示例
- Swift Set sorted(by:)用法及代码示例
- Swift Set suffix(_:)用法及代码示例
- Swift Set shuffled(using:)用法及代码示例
- Swift Set starts(with:)用法及代码示例
- Swift Set subtract(_:)用法及代码示例
- Swift Set split(separator:maxSplits:omittingEmptySubsequences:)用法及代码示例
- Swift Set sorted()用法及代码示例
- Swift Set remove(_:)用法及代码示例
- Swift Set prefix(upTo:)用法及代码示例
- Swift Set update(with:)用法及代码示例
- Swift Set formIntersection(_:)用法及代码示例
- Swift Set dropFirst(_:)用法及代码示例
- Swift Set joined(separator:)用法及代码示例
- Swift Set min()用法及代码示例
- Swift Set elementsEqual(_:)用法及代码示例
- Swift Set init(arrayLiteral:)用法及代码示例
- Swift Set min(by:)用法及代码示例
- Swift Set joined()用法及代码示例
- Swift Set isDisjoint(with:)用法及代码示例
- Swift Set contains(_:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 Set symmetricDifference(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。