Key Concepts

Review core concepts you need to learn to master this subject

Array

var scores = [Int]() // The array is empty: []

An array stores an ordered collection of values of the same data type.

Use the initializer syntax, [Type](), to create an empty array of a certain type.

Arrays
Lesson 1 of 2
  1. 1
    We live in an increasingly connected world where information flows between us and the apps that we interact with every day. Historically that information was stored in filing cabinets but, today, m…
  2. 2
    In Swift, an array stores values of the same type in an ordered list. To create an empty array of a certain type, we can use the initializer syntax: var name = Type Suppose we want to crea…
  3. 3
    We learned one way to create an array, but there’s another. We can also declare and initialize an array with a list of values, separated by commas, and surrounded by a pair of square brackets. Th…
  4. 4
    Now that we have an array, how do we retrieve an individual value? This is where index comes into play. An index refers to an item’s position within an ordered list. Arrays in Swift are zero-ind…
  5. 5
    Properties in Swift, allow us to access a value that is specific to a particular structure. We can use the .count property o…
  6. 6
    When working with arrays, we might need to add additional elements to it after initialization. We can add a new item to the end of an array by calling the array’s [.append()](https://developer.app…
  7. 7
    Previously, we learned how to add an item to the end of the array, but how do we add an item in the middle or even the start? And how do we remove an item? Suppose we have an array: var moon = [“…
  8. 8
    What happens if we want to iterate through items of an array? We can use a for-in loop! The syntax looks like the following: for item in array { // Loop body } For example, suppose we have a …
  9. 9
    [“Hip”, “hip”, “array!”] We have learned about how to store groups of data into arrays in Swift. 🙌 Here are some of the things that we covered: - An array is a list of ordered items. var evenNumb…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo