Join Harrison Ferrone for an in-depth discussion in this video Fun with generics, part of Learning Swift 3 for Developers.
- [Harrison] Let's make some new room…underneath our protocol section,…and add ourselves a comment, Fun with Generics.…Generics are all about reusability.…When you need to generalize any functionality in your code…to be non-type-specific, generics should be your go-to.…This is a fairly big subject…so we're going to do a small example…of how to make a generic append function.…
Declare a new function called GenericAppend.…Use left arrow, capital T, right arrow.…We'll come back to this in just a second.…Let's complete the function first.…Open parenthesis, and our GenericAppend…is going to take in an item, also of type T,…and an itemArray, also of type T.…We're going to return an array of type T.…The T, in this instance, is the placeholder…for the type this function will be acting with.…
It's important that both of our item and itemArray…are of the same type.…Inside the GenericAppend function,…we're going to create a new variable called returnArray,…and we're going to set this equal to itemArray,…then we're going to actually do the append.…
- Starting a new playground
- Printing to the console
- Declaring variables
- Working with numbers
- Using strings
- Breaking down optionals
- Understanding closures
- Classes vs. structs
- Extensions and protocols
Skill Level Beginner
1. Hello Swift
2. Back to Basics: Variables and Operators
3. Collections, Tuples, and Enumerations
4. Working with Logic Flows
5. Only in Swift: Optionals
6. Functions, Closures, and Associated Types
7. Classes vs. Structs
8. Advanced Topics
- 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.