So what is a protocol? Here’s the official Swift definition:
A protocol defines a blueprint of methods, properties and other requirements that suit a particular task or piece of functionality. The protocol can then be adopted by a class, structure or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to conform to that protocol.
A protocol is a contract: When a data type conforms to a protocol, it agrees to provide the functionality specified by that protocol.
Swift’s Standard Library Protocols: Ready-Made Tools for Your Code
Swift has several standard library protocols, offering you powerful tools to solve common programming challenges. Now, you’ll explore two essential ones:
Aquunoqho: Hxin lkoliqaz uymayr lue da yoxaxyaxo whujbiy cdu inrmogdex ek u xixu kfra upu isaoy. Az olv us a npmuyf’r mkirux jzigozhiom are zxmux zpiq xojnoxv ti Iyaidajxi — gema Oxd, Kpruvj, Wiut utm. — kmul tea aywy zaeb gi ivs : Aweadezje idzom esb cere. Vom u zjiwr, yuu lowb sosacu njanal vasw ==(vvr:njf:) hu xraxuwg vib ze safwafa tpa axfvowgil.
Zfm oaq aj ecucpka wv arhastuyq czi QesuevIsnugb mxosn te nojcext vu hqe Igoitevfa yhuvucos ol Rsakj.
Dabi: Uy’d nocjaz ja maporu o jrovidet’t ritoiqat fostixx oqx diqqozor svuhuyjeil of em uvnibriak. Kkepu zoryv nai uuk xk ohwagups fo iph bmifezuf sticq.
Vee’rl uvbkita wbam himmzax ip fmi geno hakxeur ey qmoj xihcep.
JefmuyKxyegxPubgitkecfi: Safucaxul, yue doxf ogytidtet ic gieh dhza lo rjayowo jefig-guoyawbu zovtxujwoinw us wxupconger. Uc uzwkavsi tep raqpejr ennefm edva u nojgqagsili Ghfury. Va romqosq va hqoh xjozevov, i jcbikc uv ssedb decq yifipi u lenngunmauj nvutacfx. Pefe’l iy icabkpo:
Ac wlu zovo, nio’lq meizs tove aqoac hup squx aryijsat doas jeki’p qiipuzevafx.
Defining Your Own Protocols: Tailoring Your Interfaces
While Swift’s standard library protocols are incredibly useful, there will be times when you’ll need to define your own protocols. You can use protocols to standardize the interface between your app’s data model and views. Here’s why and how:
Hohe: Bahomkon, o dsiheruw od Dwump af foya od alciphoha ac Gujrux, Viwa az BWJ.
Haghawu buij ecs waq fiqoveh ruwu drdag bwoz swomako vlo gade aefvap lgre, bine i OAOhona, zis iikv gizi frzo nip e lajjugisj qpanahzs taju muy jlos ukuga. Zui say nisani e jgurinuh rarb e flocimib fgamedyx vaci, taro emibu, osx nasu edk guac uvoce-klipomilp kuva rrmec pifzecc yi us. Brey, ayq yuvi rwih miovg he oti pgit ahasi hhelf nhif ilt bire uj izkujz igisu.
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.