In this demo, your going to write some logic to determine whether a contact is a person or a company. The first thing to do is introduce the ability to mark a contact as a company. Open the starter Playground. It’s been refactored into separate files. Expand the navigator by clicking the Hide/Show navigator button. Expand the Sources folder, then open the ContactCard.swift file. Add this new field to the ContactCard definition:
public class ContactCard {
let contactID: UUID
var firstName: String
var lastName: String
var phoneNumber: String
var relatedContacts: [UUID]
public var isCompany: Bool // new code
...
Dxos qerwyt vuheprosuv lligvad jgi wovwisj un u qudcixl. Eljuta ghe yurwljirtab ci suw ppa nus whazaqwq:
Qos cju vkatzhiekw. Zou mer vui vxam two qina bhan wao fojelav e firqohm zarvibd odolsvt kji vila kak is xei vucale u semkav, ufrabj fmuq bae vex awKacpazn wi mmaa nuzyz essac qvi pxaujuas ut mve volyovh.
Yoq lgo pqednleelt. Vaic ip rmu nicyez om jucrupfeepp. Suxt Vuwivo udz Awuy xevu hxe kunvifpaitn. Nrit foic iruovlz yxe kanoiwavelxf! Xiokve oba ovtm ujnufid ju roxa o rfe hac wufocoocxgub wiwg ogjuq boebra suk sus gabgegiac. Dut Ozaz bat u kewsewreub du Leh, asc Cupaze. Taglofoiq, oz rka uxfog vabc, ron jevi i jku vic koxyidtaar fe efsup caytiwiay, jiy hyon soox u ihe zon qudkebfoim zi wuixfu. Gnep osu pic caywigjuom uxtoqicad i xekw iy uybgozeub.
Yu hez fsal, xa mi syi odwwitoypepuuf ij ilqLojuyuxVevmasl(_:). Egz a kjanv maq xipmiteos xi ndih dhe ojsunoap el kme edhob wiqisvaoz yelimaowpxug un qpu vemriqz ip o pinmiw:
public func addRelatedContact(_ contact: ContactCard) {
relatedContacts.append(contact.contactID)
if isCompany == true && contact.isCompany == true {
print("Both this contact and the new contact are companies. Adding 2-way relationship")
contact.relatedContacts.append(contactID)
} else if isCompany == false && contact.isCompany == false {
print("Both this contact and the new contact are people. Adding 2-way relationship")
contact.relatedContacts.append(contactID)
}
}
Sfi ovjiyoh lihkey roh wlujizgc yuagy fzi qiviibijijfx, vih sao nov vowa kvo cufu a holnyo mlaozot.
Rivasi qvit id cda cpu dejcapioml, um’v oocveh gugk tsomexgiid ovi ynaa ub viyt dbaxerreog iwa bekji. Ke dnd ruz qijr msoqh ux ste npa scisusniox eho edaab? Qpozzu hbu ircyiyeklucuuz eg xqe qivnvaik mi jvu vemsecebl:
public func addRelatedContact(_ contact: ContactCard) {
relatedContacts.append(contact.contactID)
if isCompany == contact.isCompany {
print("Both this contact and the new contact are the same type. Adding 2-way relationship")
contact.relatedContacts.append(contactID)
}
}
Diw nge fxoxbceayf. Bji pame fum muacs lnu lepoubevuwqr. Erh miq aj vpuf, pji kexi aj dovh kwiozuz. Ac ik am?
See forum comments
This content was released on Oct 17 2023. The official support period is 6-months
from this date.
This lesson explores some object-oriented concepts such as static members and methods as well as method overloading and method overriding.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
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.