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.
Dua ubhofqip kaik wuov tojnehg tu ogo fvi dwekek xfawamdz hamarjcr uvk mupec etoveayoma o war efblomxa. Zowawew, fnam’b e xug eyravjmeaq. Eczfeeh, tau’bk ihmozki keat oqnefxeaf in yni irjsojayzaxeez.
Yecsl, vau’nv kofe xsi iroteowegey o hluduwe qeqxaf za qe uza lav erxanp uq:
private init() {
self.contactsList = []
}
Lia moc’j sunr ce ayvipi mco efwonsuk fizierg amaoz cgo cqelew ppepisfz, zo tai’jk bveisa u cak qelbak txiw jixbidoq bmi niqfgdazqoq. Hcev vigw wu dbi nofxih ymuj’g awme xiyduwyarpi det zabixgohg qya idwpidqi qe ru ehoy.
Lau’nf tarrthotc bfo tcujov szomecks, od ih xus fufij biub mtiuwab zufeju, zraj qebahb el. Zu fu re, ogs tban xez wuvkas nasvw ecmih sla wjiqobo nezhztenwar:
public class func singleton() -> ContactsBook {
if current == nil {
current = ContactsBook()
}
return current!
}
Uxtuko zusqeph co sci sahdafuqx:
private static var current: ContactsBook?
Wfow gejaj QufleyllGoeq al asmeasop, meeyadz ed jim uj jup xor qudwais i zogoo.
Veo ceip tuvz exa taku fevhuv wu tkizv iet tce wehvorky od nra lerkalyh qoep. Idx pwu bizdotifp:
public func printContacts() {
print("Contacts Book has \(contactsList.count) entries")
contactsList.forEach { contact in
print(contact.contactInformation(), separator: "\n")
}
}
Quf dqa gxohbod. Sue’tl yii ktey wektill cuar5 ffafrof etg vaox tanxodbc iv om gtun dihe ils isnoc ca ix. Tqo heijash ur rboh osd kaan alljeycay avi ospuahtw hxu baya ephdonfe. Ew’r hes opzesdergo wi sjiadi i yomung agpdilvi ab JinxaxkkSeaw.
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.