Swift: count Property

count Property in Swift:

In Swift, properties allow us to access a value that is unique to a specific structure. The count property of an array can be used to get the number of elements in the array in Swift.

Let’s say we have an array called goods that contains some grocery items:

var goods = ["flour","sugar","melon","rice"];

When we print goods.count the output would be as follows:

print(goods.count);   // Output: 4

This property proves to be more useful when the array is long.

Helpful Tools:

Here are some useful tools to help you along your journey!

Setting up an IDE (Integrated Development Environment) can be difficult for beginners. The Online Compiler will enable you to run your code inside your browser without the need to install an IDE. If you need a more detailed explanation of a specific topic, the best place to find answers is in the Official Documentation.

Scroll to Top
%d bloggers like this: