Skip to content
KnowledgeCity

Swift Intermediate: Data Structures in Swift

Learn data structures in Swift.
Preview the first lesson free — get full access to all 5 lessons.
Course: On-Demand
Intermediate Provider Mark Nair  5 Lessons ·  38m  in Arabic, German, English, Spanish, French, Portuguese, Chinese 

Course Description

Swift has quite a few ways of helping you structure your data. In this module you’ll learn about Swift Structs, first with a review of the struct syntax and organization. Then you’ll learn about the difference between value types and reference types. Structs are value types, which means when we create an instance of a struct, that particular instance keeps a copy of its own data. On the other hand, classes are reference types, which means when you create an instance of a class, all instances share a copy of the data.

You’ll also learn about CustomStringConvertable, which is a protocol you’ll use to return a descriptive string value from a struct even though the struct looks like it won’t return a string.

You’ll learn how to create and use a Stack, a very traditional data structure used by many programming languages, and you’ll learn how to create and use Generics, which will help you break away from using a highly specified type for more flexible code.

What You'll Learn

  • Review Swift struct syntax and organization
  • Explain the difference between value types and reference types
  • Use the CustomStringConvertible protocol to return a descriptive string value from a struct
  • Create and use a Stack data structure
  • Create and use Generics for more flexible, less type-specific code

Key Takeaways

  • Swift offers several ways to structure data, including structs, classes, stacks, and generics.
  • Structs are value types, so each instance of a struct keeps a copy of its own data.
  • Classes are reference types, so all instances share a copy of the data.
  • CustomStringConvertible is a protocol used to return a descriptive string value from a struct.
  • Generics help you move away from a highly specified type so your code can be more flexible.

Frequently Asked Questions

What does this course cover?

This module covers Swift structs (including struct syntax and organization), the difference between value types and reference types, the CustomStringConvertible protocol, and how to create and use Stacks and Generics.

What is the difference between value types and reference types in this course?

Structs are value types, meaning each instance keeps a copy of its own data, while classes are reference types, meaning all instances share a copy of the data.

What skills will I gain from this course?

You will gain skills in Data Structures, Data-Structured Language, Semi-Structured Data, Structured Programming, Structured Text, and Swift (Programming Language).

What lessons are included?

The lessons are Review of Structs, Value Types, CustomStringConvertible, Using Stacks, and Using Generics.

What is CustomStringConvertible used for?

CustomStringConvertible is a protocol you use to return a descriptive string value from a struct, even though the struct looks like it won't return a string.