How to check if a set is empty in Swift? Last Updated : 02 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Swift supports the different types of generic collections and set is one of them. A set is used to store unordered values of the same type. It means you are not allowed to keep different types in the set. You can use a set instead of an array if the order of the values is not defined or you want to store unique values. It doesn't keep duplicate values, it always keeps unique values in it. It generally uses a hash table to store the elements. We can also check if the given set is empty or not with the help of the isEmpty property. This property returns true if the given set is empty or returns false if the given set contains some elements. Syntax: setName.isEmpty Here, setName is the object of the set class. Return Value: This property will return true if the given set is empty or return false if the given set contains elements. Example 1: Swift // Swift program to check if the given set is empty or not import Swift // Creating an set of EmployeeSalary // Here the set is of int type var GEmpSalary: Set = [30000, 12200, 14000, 67800, 10000, 90000] // Checking the given set is empty or not // Using isEmpty property var result1 = GEmpSalary.isEmpty // Displaying the result print("Is the GEmpSalary is empty or not?", result1) // Creating an empty set of int type var GEmployee = [Int]() // Finding the total number var result2 = GEmployee.isEmpty // Displaying the result print("Is the GEmployee is empty or not?", result2) Output: Is the GEmpSalary is empty or not? false Is the GEmployee is empty or not? trueExample 2: Swift // Swift program to check if the given set is empty or not import Swift // Creating an set of Authors Name // Here the set is of string type var GName: Set = ["Minaxi", "Prita", "Mona", "Guri", "Om", "Rohit"] // Checking the given set is empty or not // Using isEmpty property if (GName.isEmpty == true) { print("Yes! the given Set is empty") } else { print("No! the given Set is not empty") } Output: No! the given Set is not empty Create Quiz Comment A ankita_saini Follow 0 Improve A ankita_saini Follow 0 Improve Article Tags : Swift Swift-Set Swift-Functions Explore Swift IntroductionSwift - Hello World Program2 min readSwift - Basic Syntax5 min readSwift - Keywords4 min readSwift - Literals10 min readSwift - Constants, Variables & Print function2 min readSwift - Operators8 min readSwift Data TypesSwift - Data Types5 min readSwift - Integer, Floating-Point Numbers2 min readStrings in Swift8 min readString Functions and Operators in Swift10 min readHow to Concatenate Strings in Swift?3 min readHow to Append a String to Another String in Swift?2 min readHow to Insert a Character in String at Specific Index in Swift?2 min readHow to check if a string contains another string in Swift?2 min readHow to remove a specific character from a string in Swift?2 min readData Type Conversions in Swift5 min readSwift - Convert String to Int Swift3 min readSwift Control FlowSwift - Decision Making Statements5 min readSwift - If Statement3 min readSwift - If-else Statement3 min readSwift - If-else-if Statement3 min readSwift - Nested if-else Statement4 min readSwift - Switch Statement10 min readSwift - Loops5 min readSwift - While Loop2 min readSwift - Repeat While loop3 min readSwift - For-in Loop6 min readSwift - Control Statements in Loops5 min readSwift - Break Statement6 min readSwift - Fallthrough Statement4 min readSwift - Guard Statement15 min readSwift FunctionsCalling Functions in Swift6 min readSwift Function Parameters and Return Values10 min readHow to Use Variadic Parameters in Swift?6 min readSwift - In Out Parameters4 min readSwift - Nested Function5 min readSwift - Function Overloading8 min readClosures in Swift9 min readEscaping and Non-Escaping Closures in Swift5 min readHigher-Order Functions in Swift10 min readSwift CollectionsSwift - Arrays9 min readSwift - Arrays Properties4 min readSwift - How to Store Values in Arrays?4 min readHow to Remove the last element from an Array in Swift?4 min readHow to Remove the First element from an Array in Swift?4 min readHow to count the elements of an Array in Swift?2 min readHow to Reverse an Array in Swift?3 min readSwift Array joined() function3 min readHow to check if the array contains a given element in Swift?3 min readSorting an Array in Swift5 min readHow to Swap Array items in Swift?2 min readHow to check if an array is empty in Swift?2 min readSwift - Sets15+ min readSwift - Set Operations9 min readHow to remove first element from the Set in Swift?2 min readHow to remove all the elements from the Set in Swift?2 min readHow to check if the set contains a given element in Swift?3 min readHow to count the elements of a Set in Swift?2 min readSorting a Set in Swift4 min readHow to check if a set is empty in Swift?2 min readHow to shuffle the elements of a set in Swift?2 min readSwift - Difference Between Sets and Arrays3 min readSwift - Dictionary9 min readSwift - Tuples3 min readSwift - Iterate Arrays and Dictionaries6 min readSwift OOPsSwift Structures7 min readSwift - Properties and its Different Types13 min readSwift - Methods5 min readSwift - Difference Between Function and Method4 min readSwift - Deinitialization and How its Works?4 min readTypecasting in Swift7 min readRepeating Timers in Swift4 min readNon Repeating Timers in Swift7 min readDifference between Repeating and Non-Repeating timers in Swift4 min readOptional Chaining in Swift9 min readSingleton Class in Swift4 min readSwift Additional TopicsSwift - Error Handling2 min readDifference between Try, Try?, and Try! in Swift4 min readSwift - Typealias7 min readImportant Points to Know About Java and Swift3 min readDifference between Swift Structures and C Structure4 min readHow to Build and Publish SCADE Apps to Apple and Google Stores?11 min read6 Best iOS Project Ideas For Beginners8 min read Like