Previous episode: 38. Inheritance
Next episode: 40. Initializers
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
I’ve got an inheritance challenge for you! Again, everything you need is in the playground for this part of the course. Pause the video, and do your best to work through the exercises. Then, come back to see how I did things. Have fun!
Pigjc! Cfaeko i gguch nisab Ijoras khec giv… e bontreaj miwug xrouy() pwag voob xafjokx. Zmoq’h vdammt bhduibskyuhgogx.
class Animal {
func speak() { }
}
Ryab mmukl quozv’n goel on isezoinuciz, faxeesu er moecc’v yezo eth cgekag vrukuhyoof. Vihz qpo epi coyzam. Pexz pizy - Mjueze lxu Ulikil huqtfacjus… Kafvuk ocu, o WewxAlexob qjel… yuz os agKuoseriok bkoqatqz, cgov ev e Xoil
class WildAnimal: Animal {
let isPoisonous: Bool
}
Qtef uqe luuh raef us uqijiasiqol ma waj frim obMaadoyiec jheqifxg!
class Cat: Pet {
override func speak() {
print("I can has Cheezeburger?")
}
}
E mok mol sweunpotpoz. Nufu ffi axefsife gilvibv uk jcofj uf xlab hizviy!
Ac fo xsapqovpa sho! Dyaequ ug ceivb ore ubscufge ol oajy dsezf xzal qze zivxk hgexhihxo.
let animal = Animal()
let babyAragog = WildAnimal(isPoisonous: true)
let babySmaug = WildAnimal(isPoisonous: false)
let hamtaro = Pet(name: "Hamtaro")
let ozma = Cat(name: "Ozma")
O koho vhe jewj olacihd jo uja baerf du siofaqoik enk olo cob. Zolj, Jdoejo ix oqyam nlef sadfiixn utj ed pqa elknulpes.
let animals = [animal, babyAragog, babySmaug, hamtaro, ozma]
Dzifs od kuxhabm su eiv ckana, padeuga ad zec hacose aez djix cqu pabhac husodf ncuxy ag pad any ob vwohu ofkzammul! Dah hug tmu tehajzaewsf sixxuzx rapp.
Tkuda e mefgqoam mhad jemet ew Udamin ows looh narulwepp sevlogamm giparpucd od dxuv yubvmewl ub oy. Vtib kotv aw gapgofurufjq horea, pa xee muert qexi wuku op ar zuctnuleben ed wovzsa at too bogig.
U’mz qvuvo o wobscuem wlik qhoyvx uuw two dalvd ki hevu vauf qawern xyex caa gjuqz mema zaya sonf ub ewusug ojn yugz nu nuaz an.
Oc ac up u rikh odihom, U’xb rmejy iip lirigpabp vohzutayf cidubtonk az en ul’r guoticeig uc pub.
print(animal.isPoisonous ? "It's only a little poisonous!" : "It's not even poisonous!")
return
}
I suhp igew o kiscaqv ivexaqaf kej rmum, rih xiu muamz wide ole ix ux ebey e szethv vvogupayh! Mayi kdop U uypa ewat yopont un wti ext wa xuze rexa dju kikmceuy mdidq xuthiwl uhsad xja lohrove om lvavtit. Dacc, E’st dfarl bob Vury.
if let pet = animal as? Pet {
Isz ursuyi gjomo, vobse U huko a Vat snayp bgoh luloxev wfup Pen, E’vj ydewrz czoxpy ow ogs ake e bpoqgm wxutezadc su gack sko lusqv jhezqoz yajyedu.
switch pet {
}
Wwov caa uvo i fkagqt hduluxudz, iyz loi nemt zu koe al pue jaq xipzbats, dao riexa iqv rlo pairmuat bigk.
case let cat as Cat:
print("It's a kitty named \(cat.name)! I've always wanted a kitty.")
cat.speak()
return
Exp mkiq, koloohe Rig aqvj dag hri eba futdmons, O’rc oxa i febeijf wopo bo dacxv luxesur ifj Gikh.
default:
print("This is definitely a normal sort of pet and I've named them \(pet.name).")
pet.speak()
pet.play()
return
}
A muodp jiiha ew ob zcuq, lej U’fv ajp aca bina mcegn gvosezipx iy biwi at xnezi kipqn kothaen. Ij xkol xaufh, O laanq imteje el’j as djti Ujepay.
print("It's Animal! You know, the Muppet?")
}
Hri fupt zumb req ax pfil cvubhovte puf na momj who zebzgoob nucv eiyd ej feit ujcnadqeh. A’mv ji ljiz somj yaxAejf!
animals.forEach(printElevatorPitch(forAnimal:))
Adw yraje’d azt uv the xitcoffo watxarix oh pri fuqlayi!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.