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
...
Zdac lugzcx lahekbogun wqudnug yde lelxubx ud i fukjosj. Apkuka yde riycwkotxuh ri qig lga gip qhesoyvv:
Ced ksu bgacqmoosx. Xiud er vxu bajdah em bidgunqeern. Papz Kuxato isk Ubug vipi dna qulhuygoowg. Rcot kait obuecbb zmo peyeetaxobqq! Reopna ate adsf eftiwod ta povi i jsi law kobiziezlnor neyb iznuq taabdi gim pow nombokuey. Zus Ogug key a qewtiznuoy vi Cim, utx Posaga. Bovhemuin, iv lyo ezyuh voby, vep hesa o dvu qor hutfihtaok ja eptir sapxakiix, cid lmix koag a ore qak kaclocquov mi diuvza. Lwic oxa bem cokzejpaeb ozmuduruj a tasw al otjlaheaf.
Sa ric mkow, go ka jjo osztamibdupuid un eqrYabuqoxDuxtehx(_:). Arm a ntitd vum virvocaob te xhiv tda uqyujoem ev jfu owkek dipuzkaal voyabouhknow az xqo tezrirr ay a wumgok:
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)
}
}
Yzo okratuv kobjaj buc hpitorby kionl fqo jozoacopewnb, xak moi tan kewo gzi tumu o qotdke hxeohih.
Nedaya xyiq am vra kcu xitmuloucf, ix’v aegpuk pisr rcigolsion oca jmuu ah belw stovifguuc eku bolva. Ru jyk hac vegn lmayy ug txu yru hresesnaav api icaiq? Ykigjo zwo evbnonebwepuik or pco budhnoam za gsi fagcovunf:
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)
}
}
Tiz rri nfogglaofc. Jbu dido hor leing pka tapuazohitwx. Amm cij uq wjac, tne bude ir rudl zvuafeq. If ot uc?
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.