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.

  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…
  1. 1
    Imagine walking through an art museum and finding two identical Mona Lisa paintings hanging on the wall. That situation would most likely cause a few raised eyebrows. Art museums should only cont…
  2. 2
    In Swift, we can initialize sets that are either empty or populated with values. A set that has been initialized without any values inside of it is known as an empty set. Empty sets are useful …
  3. 3
    We can use different built-in properties to help us understand information about specific collection types, like sets or arrays, in our programs! For example, we can use .count to find out how man…
  4. 4
    If we want to add new elements to our set, we can use Swift’s built-in .insert() method. Being able to augment our sets with new elements is useful when we have additional data to store or when w…
  5. 5
    If we need to remove an element from a set, we can use .remove(). This method can remove a single item from a set with the following syntax: setName.remove(Value) Let’s revisit the set plantShelf…
  6. 6
    If we want to check whether or not an element exists within a set, we can use the .contains() method. We can use the following syntax to check for an element inside of a set: setName.contains(Valu…
  7. 7
    If we want to go through every individual value contained in a set, we can use a for-in loop! To iterate over every item of a set, we can use this syntax: for Value in setName { // Body of loop …
  8. 8
    In Swift, we can use set operations to create new sets based on the data within two different sets! This is useful when we are working with multiple data sets. We can use the .intersection() metho…
  9. 9
    Another set operation we can use is .union(). This operation creates a set by combining the values of two sets together. The syntax for creating a set using .union() is: var NewSet = SetA.union(Se…
  10. 10
    The .symmetricDifference() operation can be used to find elements that exist in one of the given sets, but not both. The syntax for creating a set using .symmetricDifference() looks like this: var…
  11. 11
    Another set operation we can use is .subtracting(). This method creates a new set of elements by removing the overlapping data of one set from another set. To use .subtracting() in our program, w…
  12. 12
    Great job completing this lesson! Let’s go over what we learned: * A set is an unordered collection of unique elements. * We have the option to initialize sets that are either empty or populated: …

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