Declare a class with inheritance

 Problem

I have a parent class and want to create another one which "inherits" it.



 Recipe


// Create 'parent' class
class Animal {

	func sayHello() {
		print("Hello")
	}
}

// Create a child class
// which 'inherits' our parent class
class Dog : Animal {

}

// Create a new Dog instance
let myDog = Dog()

// We can also access its parent's methods
myDog.sayHello()
				

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)

 

 Playground