Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Swift Set isSuperset()
In this tutorial, we will learn about the Swift Set isSuperset() method with the help of examples.
The isSuperset() method returns true if a set has every element of another set (passed as an argument). If not, it returns false.
Example
var A: Set = [1, 2, 3, 4, 5]
var B: Set = [1, 2, 3]
// check if A is superset of B or not
print(A.isSuperset(of: B))
// Output: true
isSuperset() Syntax
The syntax of the set isSuperset() method is:
set.isSuperset(otherSet)
Here, set is an object of the Set class.
isSuperset() Parameters
The isSuperset() method takes a single parameter:
- otherSet - The set of elements.
isSuperset() Return Value
- The
isSuperset()method returnstrueif set is a superset of otherSet. If not, it returnsfalse.
Example: Swift Set isSuperset()
var employees: Set = ["Sabby", "Cathy", "Kenny", "Sammy", "Lanny"]
var developers: Set = ["Sabby", "Lanny"]
var designers: Set = ["Cathy", "Patty"]
// check if employees is super set of developers or not
print(employees.isSuperset(of: developers))
// check if employees is super set of designers or not
print(employees.isSuperset(of: designers))
Output
true false
Here, we have used the isSuperset() method to check if one set is a superset of another or not.
Since
- employees is a superset of developers, the method returns
true. - employees is not a subset of designers, the method returns
false.
Did you find this article helpful?