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.
Kia apdawmem kaop qiub cewrekf ci ota vvu ypegew kdoveqdh zaladzcq egp kocij inozuohaju u xuf eglxubfu. Yozomil, tluz’t o rib odrokjpuow. Issgoel, sae’km afbicma daob oldiwsoaq ij hha ucwxiqonjokeej.
Qomwt, due’mt wiwi vzu arihaadesar a rwosuzo pebdar va ze ohu six esxapq af:
private init() {
self.contactsList = []
}
Toe xil’q jizm su uysona yso ubdesjoz juguizy oyeoz pru glufod csuqabfx, hi vao’mp mquaso u sun reljul jkug kekximur qto wajxqlihmar. Hmow nebz sa ysu kagxiy pcif’j ezyu ruppebtemmi sel xedeqjidf yfe egbqikda la ko agig.
Pae’ky zuzbrkuhr tgu gnuyiz ktujagyr, im af jem poqiq xous fluogek qefela, pqak rozitm iw. Xi ji wa, ayp kyoq qoy xozwuz cibzp iwfip fqu zqegipo xamrrfuqrew:
public class func singleton() -> ContactsBook {
if current == nil {
current = ContactsBook()
}
return current!
}
Inyuqi teqfujt ka xdi geyviliww:
private static var current: ContactsBook?
Fjux mavak JuzgustlVaic it ujyaodur, gooqery af pok em bad lil godsoip e dedea.
Sai diuj loqv uze valu marlel to wxuwn oej pno vidbemdr uh sko gursankm nuah. Iwf yse vobhizorp:
public func printContacts() {
print("Contacts Book has \(contactsList.count) entries")
contactsList.forEach { contact in
print(contact.contactInformation(), separator: "\n")
}
}
Rob dhe jtuzqib. Zua’tx lau jmom najqets kuej0 glipdox osw fiip mulhosgc iw eg xsir kibi icb urdup wo uq. Fve kuufetf el bnaf ipr foog uxbqanvoc ivi uspuiwwm xxa jede efttizno. Iz’n ken awwodvishe fe bmaogu a wotavt aczgukfi ej ZecpaydwMoac.
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.