How to count the elements of an Array in Swift? Last Updated : 02 Jun, 2022 Comments Improve Suggest changes Like Article Like Report In Swift, an array is an ordered generic collection that is used to keep the same type of data like int, float, string, etc., here you are not allowed to store the value of another type. It also keeps duplicate values of the same type. An array can be mutable and immutable. When we assign an array to a variable, then that array is known as mutable whereas when we assign an array to a constant, then that array is known as immutable. In the Swift array, we can count the elements of the array. To do this we use the count property of the array. This property is used to count the total number of values available in the specified array. Syntax: arrayName.count Here, arrayName is the object of the array class. Return Value: It will return the total number of values present in the given array. Example 1: Swift // Swift program to find the total number of elements in the array import Swift // Creating an array of Authors Name // Here the array is of string type var AuthorName = ["Tina", "Prita", "Mona", "Guri", "Om", "Rohit"] // Finding the total number var result1 = AuthorName.count // Displaying the result print("Total number of authors:", result1) // Creating an empty array of GEmployee Name // Here the array is of string type var GEmployee = [Int]() // Finding the total number var result2 = GEmployee.count // Displaying the result print("Total number of Gemployees:", result2) Output: Total number of authors: 6 Total number of Gemployees: 0Example 2: Swift // Swift program to find the total number of elements in the array import Swift // Creating an array of Authors Name // Here the array is of string type var AuthorName = ["Tina", "Prita", "Mona", "Guri", "Om", "Rohit"] // Using count property if (AuthorName.count > 3) { print("Array contains more authors name") } else { print("Array contains less authors name") } Output: Array contains more authors name Create Quiz Comment A ankita_saini Follow 0 Improve A ankita_saini Follow 0 Improve Article Tags : Swift Swift-Arrays 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