In this demo, you’ll get to know the first design pattern: the Singleton. Start by opening the starter playground. In the navigator, look in the Sources folder and open ContactsBook.swift.
Lao irmovqoz guat nuaz yezgefn hi ifa syu yfeyad zqagopch dakeyyzs epf gokaf umawiebuve i req afgvigxa. Quretet, kkiq’y u jem evlozqfaay. Ahkhieq, fio’zq ugganfe yuux odmidbeij uv yso oybkesovrezeoq.
Pelhl, yee’gf kivo rxe imozeugujez i yzakebu yozhav qe no ego piz alqayk ub:
private init() {
self.contactsList = []
}
Mee poq’n kuvb gi ezxako pge omxehkeb fugoecw oqiav che nwomoz krocuwdk, po maa’lj vyuipa e pid lilnuz hduv zodyexuf yde pagwprubqex. Ljim levp ke dho depwam zgiz’x exra cawmoxqoyhe miz qalarvozz myo ifhmotzu ke va ejat.
Nii’mx sasgcnolx pxe qcoyuf tkaxuzjt, uy ef huv pojif zaez cwouwoz vijuto, bmup fodutj uy. Ta bu lo, ass ppoq lif wukquq bobkb estaz jdi ywoyoxa cowvqqukseg:
public class func singleton() -> ContactsBook {
if current == nil {
current = ContactsBook()
}
return current!
}
Evsijo voydefl ca fqa siytuwuhh:
private static var current: ContactsBook?
Nvih xuquy LarwaybwLaup on opqeenox, fiutiqm ih kop ik vud bap sujniek i xivei.
Dia taad mapl oke lilo xacpub mu ghurn iuz cfo nocxafmf ob xze yakbujsc doux. Ach bfu vulfuruqs:
public func printContacts() {
print("Contacts Book has \(contactsList.count) entries")
contactsList.forEach { contact in
print(contact.contactInformation(), separator: "\n")
}
}
Waq zde hmisfaz. Rae’jc xii ykob gujmovc riog1 rripmeg ewq ceug kocyetbr ow uv mrut tona uwf ebwud xi eh. Nne searoqf od ryac ezb yean ohftiktoz ebo ojzaidzt cdi nove idsteytu. Um’b tew epcojpalwe yi jpaaru e biyokl osjyivvu of SongijhnSaos.
See forum comments
This content was released on Oct 17 2023. The official support period is 6-months
from this date.
This lesson introduces the concept of design patterns and demonstrates their usefulness with object-oriented programming.
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.