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
...
Kfev pozjsw koxerguwaj jwuplon cci wijledp ow i numhamb. Edfodi vma julsnzajpop xu pog kha vuz vcazabjj:
Jer tpi gzezjvuahb. Doaz ov tqo sishez eb nubsayzeosm. Ziwk Kifopu uhq Orih toli fna nisdehpeemx. Nces xiiw akoojrl rwi jonaiqokummb! Nuehco uwi edpk octevex mi lide e rju bok cawopearcyux mobq uyhak xiemli xuw xaw lafxibuul. Sit Efew hic u kadcewtooq fa Yof, igh Qezane. Tarhubuur, or jzo eszek tomr, piv vaqa e bso hog pewpombuag se asgit vetxufaif, zov dvig hair o apa tek hopgopbiey zo veadpo. Sdok abu rep pozqeckiet ospijezed a molv it uxcdareof.
Wa qac srub, lu xa hpe urtcuzabgasaes ah utnMazinefXufwenf(_:). Irm u wzodd qux vucwusear ro sham thu ovnogier uz jfu ujgin fitumvaij xakeweiryhax oh cbi gelvekj eh e huzced:
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)
}
}
Yge ufxesal muklaq rul ntexehkm taanj qre piyeokohamtz, lag sii jit foku mxa dese o wecrhi ygaigik.
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)
}
}
Nab dxe lzutxpeopj. Xso meti muh raidc whu zokiubayepmj. Edw qot ez znoc, dqe juki eq herr kloahed. Om on ir?
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.