Swift Programming: The Big Nerd Ranch Guide by Mathias Matthew & Gallagher John

Swift Programming: The Big Nerd Ranch Guide by Mathias Matthew & Gallagher John

Author:Mathias,Matthew & Gallagher,John
Language: eng
Format: epub
Tags: Big Nerd Ranch Guides, COM051370, Swift Programming, Mac Programming, iOS Programming, iPhone Programming, iPad Programming, Xcode
ISBN: 9780134689654
Publisher: Big Nerd Ranch Guides
Published: 2016-11-22T16:00:00+00:00


If the subclass implements all of its superclass’s designated initializers – either explicitly or via inheritance – it will inherit all of its superclass’s convenience initializers.

Your Zombie type falls within the first of these two scenarios. It is inheriting the Monster type’s sole designated initializer because it provides default values for all new properties it adds and it does not define its own designated initializer. And because the Zombie type is inheriting an initializer, the compiler is no longer providing the free empty initializer you were using before.

The signature for the initializer Zombie inherits is init(town:monsterName:), with parameters for town and monsterName. Update fredTheZombie’s initialization to include these parameters and remove the error.

Listing 17.9 Updating fredTheZombie’s initialization (main.swift)

... let fredTheZombie = Zombie(town: myTown, monsterName: "Fred") fredTheZombie.town = myTown fredTheZombie.terrorizeTown() fredTheZombie.town?.printDescription() ...



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.