Find out how to separate declaration from value assignment in variables and constants. Additionally, work with instances that may hold a value or be nil, using optional syntax.
- [Instructor] Up to this point…I've been assigning a value during declaration…of a variable or constant.…This is convenient but not absolutely necessary.…It is possible to declare a variable or a constant…as being of a type…but then not assign it a value right away.…This variable, wordsOfWisdom, is declared to be a String…but not assigned a value yet.…So, I'll assign a value separately…after its declaration.…The type must be explicitly declared…when a value is not assigned during declaration,…because the compiler has no way to infer it.…Multiple values can be declared on a single line…separating the names with a comma…and specifying the type at the end,…and then their values can be assigned after declaration.…
Deferring value assignment like this…even works with constants,…which I mentioned earlier are immutable…and cannot be changed.…While this is an interesting exception,…a constant can be declared and separately assigned…but only once.…ConstantString is declared to be a constant of type String,…and then I will separately assign it a value.…
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.