In this video, Scott explains how to define and call instance and type methods for a class. Familiarize yourself with good class definition organization.
- [Instructor] I'll continue in the exercise file…from the last video.…Classes can implement type and instance methods.…Instance methods are not surprisingly,…called on the instance itself…and are defined just like regular functions.…I'll add a start method that prints the sound…of an electric car when it starts,…that is, silence…and now I'll call start on my instance.…Type methods are called on the type name itself…just like properties.…
I'll add a type method that prints the current count…of electric vehicle instances.…I could have used the class keyword here…instead of static…but I prefer to use static across the board…for all type properties and methods…just to keep things consistent.…And now I can call this type method…to print out the current instance count.…
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.