Continue learning about functions in Swift, including how to return compound values, pass as parameters and return function types, and how to improve readability of complex function definitions.
- [Instructor] I'm continuing in the same…exercise file from the previous video.…Although I've added a couple of array values…that I'll be using shortly.…You can access the card suit emoji by selecting Edit,…Emoji & Symbols from the menu,…and searching for suit.…I'll also define a helper function,…randomIndexFor array,…that will take an array and return…a random integer index for it.…It abstracts away the necessary converting…between Int, which is the type required…to index into array, and UInt32,…which is the type required by ar4random_uniform.…
Now we'll define a function to simulate…dealing a card.…That is, a random value and suit from a deck.…I'll define the return value to be a tuple…of two named string elements.…And in the function body, I'll create…random index values to use for…the suits and values arrays.…And then we turn the tuple containing…random values from those arrays…using the random indexes.…
Now we'll assign the result of calling dealACard…to a value named card.…As you see in the results sidebar,…I can refer to the elements by index or by name.…
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.