[Swift] How to get the number of elements in an array (super basic)

ViewController.swift


//Define array
let fruitArray = ["Pineup", "Kiwi", "mango"]

//Get the number of elements in the array here
let length = fruitArray.count

//Display acquisition results
print(length) //result(3)

Now you can get the number of elements. If you can get the number of elements, you can also perform conditional branching with that number, which is convenient.

ViewController.swift


//Define array
let fruitArray = ["Pineup", "Kiwi", "mango"]

//Get the number of elements in the array here
let length = fruitArray.count

//Conditional branch example
if length == 1 {
  //Describe the processing in case of 1
} else if length == 2 {
  //Describe the processing in case 2
} else if length == 3 {
  //In case of 3, describe the process
}

Recommended Posts

[Swift] How to get the number of elements in an array (super basic)
[Swift5] How to get an array and the complement of arrays
How to get the length of an audio file in java
[Swift] Summary of how to remove elements from an array (personal note)
[Swift] How to get the document ID of Firebase
How to get the ID of a user authenticated with Firebase in Swift
How to change a string in an array to a number in Ruby
How to retrieve the hash value in an array in Ruby
How to add elements without specifying the length of the array
How to specify an array in the return value / argument of the method in the CORBA IDL file
Compare the elements of an array (Java)
How to output the value when there is an array in the array
How to determine the number of parallels
[Swift UI] How to get the startup status of the application [iOS]
How to get the id of PRIMAY KEY auto_incremented in MyBatis
How to get the date in java
Dynamically increase the number of elements in a Java 2D array (multidimensional array)
How to convert an array of Strings to an array of objects with the Stream API
Get the type of an array element to determine if it is an array
How to change the maximum and maximum number of POST data in Spark
How to find the total number of pages when paging in Java
How to get the absolute path of a directory running in Java
[Swift] How to set an image in the background without using UIImageView.
How to insert processing with any number of elements in iterative processing in Ruby
Summary of how to select elements in Selenium
Note how to use Swift super basic TableView
How to add sound in the app (swift)
How to get today's day of the week
[Java] How to get the authority of the folder
graphql-ruby: How to get the name of query or mutation in controller Note
If the parameter is an array, how to include it in Stopara's params.permit
[Swift] How to change the order of Bar Items in Tab Bar Controller [Beginner]
How to get an arbitrary digit from a number of 2 or more digits! !!
[Java] How to get the URL of the transition source
[Swift] Get the number of steps with CMP edometer
[Java] How to get the maximum value of HashMap
[Android] How to get the setting language of the terminal
[Rails] How to get the contents of strong parameters
[Rails] How to display an image in the view
[Note] [Beginner] How to write when changing the value of an array element in a Ruby iterative statement
What to do if you can't get the text of an element in Selenium
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
How to get the class name of the argument of LoggerFactory.getLogger when using SLF4J in Java
How to use git with the power of jgit in an environment without git commands
How to request by passing an array to the query with HTTP Client of Ruby
How to get the class name / method name running in Java
[Ruby] Count an even number in an array using the even? Method
An unsupported Java version How to get rid of errors
How to get the longest information from Twitter as of 12/12/2016
How to add the same Indexes in a nested array
How to derive the last day of the month in Java
How to change BackgroundColor etc. of NavigationBar in Swift UI
[jsoup] How to get the full amount of a document
[Ruby] How to batch convert strings in an array to numbers
[Swift5] How to analyze complex JSON and get the index of the element that satisfies the condition
How to manage the difference in each environment with yml without increasing the number of RAILS_ENV
How to get parameters in Spark
The basic basis of Swift dialogs
[Ruby] How to count even or odd numbers in an array
[Swift] How to dynamically change the height of the toolbar on the keyboard
[Rails] How to get the URL of the transition source and redirect