Swift .isSubset()
Anonymous contributor
Published Oct 24, 2022
Contribute to Docs
The .isSubset() method returns true if all elements of a set are present in another set (passed as an argument), false otherwise.
Syntax
setName.isSubset(of: otherSetName)
The isSubset() method returns true if setName is a subset of otherSetName, false otherwise.
Example
let set1: Set = [2, 4, 6, 8, 10]let set2: Set = [4, 10]if set2.isSubset(of: set1) {print("set2 is a subset of set1.")} else {print("set2 is not a subset of set1.")}
In the example above, the first block after the if statement will run if set2 is a subset of set1. This will output:
set2 is a subset of set1.
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Swift on Codecademy
- Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
- Includes 7 Courses
- With Certificate
- Beginner Friendly.13 hours
- A powerful programming language developed by Apple for iOS, macOS, and more.
- Beginner Friendly.12 hours