Learn how to collect unique values into unordered containers called sets, and understand the requirements in order to store a type in a set. Discover how to create, inspect, and modify sets and convert sets to arrays.
- [Narrator] Sets are unordered containers…used to store unique values of the same type.…All Swift's basic data types can be used as set value types.…You can use your own custom types too,…as long as they're hashable.…And as I mentioned in the last video, I'll go over…how to make a custom type hashable in the Types Chapter.…Sets are declared using the longhand syntax only.…To define a set, write set followed by the type…in angle brackets.…You can initialize a variable to an empty set…by writing parenthesis after the type definition.…
Or you can write empty square brackets just like an array.…In fact, a set is initialized using an array.…I've defined students to be an array of strings here.…So it is inferred to be an array.…But if I explicitly define it to be a set,…the set type can be inferred from the array…being used to initialize the set values.…Because sets will only store unique values,…duplicates will be removed when initializing a set…with an array containing duplicate values.…
I added Charlotte twice, but the duplicate was removed.…
Learn how to write code, understand Swift's key concepts and best practices, and strengthen your programming problem-solving skills. Instructor Scott Gardner teaches the fundamentals, so you'll be prepared to develop applications for iOS, macOS, and other platforms. Completing this course will enable you to not only write first-class code, but to think like a Swift developer.
- Creating playgrounds
- Defining variables and constants
- Working with characters and strings
- Working with collections and groups
- Using operators and defining custom operators
- Controlling program flow
- Defining functions and closures
- Working with classes, structures, and enumerations
- Adopting protocols
Skill Level Beginner
1. Get Started
2. Variables and Constants
3. Characters and Strings
4. Collections and Tuples
6. Control Flow
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.