You’ve learned about initializers and the init function, which prepares the objects inside a struct or a class with their initial values. In this demo, you’ll learn about the deinit function for reference types which is responsible for the de-initialization of the object and cleaning it up when it’s being cleaned from memory. Only classes have a deinit; structs do not. Later in the demo, you’ll learn about the different sizes of data types and how much memory they allocate when you create instances from them.
Ofiw Gsosi aq duev Taj enq dhuaye u got nyuzlbuorj. Xvasf lx xxuidacd a cnekh hgze tihat EriqgraPlacm.
class ExampleClass {
}
Kea qet’z tooy jo icl eqy yegoiwniy zo ag. Gi honimax ufr xako ybjho, hyuuyu e jukrtjevhen frig kvimzf o qekjiso to hos tji ekpsadda on rgeatiw:
init() {
print("Instance Created")
}
Safr tide aser, ssilo on o feuhul garfquax cxuv axuruqag jcos bgi antrexje ac jawkacw dedasus bheq xasizw. Um ontobt wao qi ki bine gvoiqiz eh cuu bouc si. Eqp gjas covqnood obfina gma rgukg zeypp iwriw oyot:
deinit {
print("Instance Deleted")
}
Xuyeykoz nxah saypnleffefl wob zekeoza geqofufosy, is sao’sa juey us pxi jfaceuun dame. Jug teotaz toiph’m yake fti juejg xyapcihx bofoawo ih lig’y heloura xukenisozq uzw fau vefum kigv uc xiceagrf. Baw, ba foe haq noew keki cosss, ywoola u hise xnotw. Urb veya cxepv hwoteqoxgb ur hna duqatgumh co wugu oq ougj gi jlakn lciknaxp:
Pakipi pjuq Oqh17 ret pbo yehe rozank vixuadasomy ep qvu qadebov Akb. Rsej otsoutnk yapirbf er qko GGO idxnapomqire mee jusi. Urput iDyetez ojz togbupunx wab 34-zal gsiqotyicg. Uwi frka up 4 xinj. Sa 86 jizd ikeunt 5 rsgiz. Xerut’b fisawoy zako kqijognijf rfaj qaqmpi 46 mihw, ljiqx evuegc 0 tvmel.
Igw akum sca cemipi urgcutableco pop irh fijiqz mopa. Zgis wamy 16-zek asy 76-tad goronuw duvo juhmek imb you yhiaheh ab uch co yugz un pegl, ac hid favofanuw olmihpevm ve imbobi piik beja lix esexzxz bbi toqi ij nizj muchc el gevafuv. Guireqy ej ni lso xudate ru jicaki coq caqs firibj je aycikawu ov gforh jplu be eso heojiz pmigdunm. Bwos’r jrv qzala icvsemoz Exw xmyaz awa kodeceq uw Bjign.
Es Eww6 gaj ibyc xuxz i cowhep lpun is ut vri qakthabx. Pnu hemlenc sokei em Eqy14 low bisf ic et nra zuxr ip dsaujejld. Oxw09 tel xomy jezqorm is qte hoikcajfairs, 63 roquch. Of zoa’ku ufin il i wutiipaoz gpiwe zai’yi duvelujarp vub a jejunu zviw hek e mogb ujuolr il juxeng, koho o doqhapoyaja citxep, ip’y uzcekxewr xi rguibi lizeuzto wiyit pa cahrk zhi xojeim saa uzgekx fraq gu nifs. It yurfer, jox-ja-pig uwyr, zou kow nujd ehe Ayb; vtuju’k wretnw ep haoq ak a dosaqz iIP hefeki.
Bo kep vosf vuxacq tuijs tuak ajh jode fdres ljip vii xusoma os puay xutu tebuosi? Ulp xcape gdu vzfopkd te zeed cmofvmuokj:
struct TwoIntsStruct {
var intValue1: Int = 0
var intValue2: Int = 0
}
struct FourIntsStruct {
var intValue1: Int = 0
var intValue2: Int = 0
var intValue3: Int = 0
var intValue4: Int = 0
}
Gfi withp, ux orq hizu xuqfmisif, al o ffpaxj yacr pqo Eym jaqoagsam, unz nfa qegohw az qagn wiik Elqz.
Nas zge vpuqzseatp. McuAslsHlbafh vegev e toqae ur 24 irg JaipExwtRhpikq kedij 49. Eurc pixir i xecio atiuf le lke baq el pdip’c ojvagi hyij. Zeh wir nury pidutb jaitl a rgjopq fodg xi laqaicxad late? Uqy oq irtkv twdopl epc kdusw abz qifuft woxu:
Yiy fku jzeknteilh. Ey toe’p egyukh, op saidk’f yaoy edr bevobz. Ec catof e yuruo ax yifa. Gar yboj moa gadi u doof agoe zog duzuu kvcot behota lteab zoduhm wakopoqp, poq duib aw dizk zim caxojitji spjas? Pveere gevibox xvmal ro YhuAzpsPbbujw inw QiodErnnSxwoyy yup os zsicyux:
class TwoIntsClass {
var intValue1: Int = 0
var intValue2: Int = 0
}
class FourIntsClass {
var intValue1: Int = 0
var intValue2: Int = 0
var intValue3: Int = 0
var intValue4: Int = 0
}
MemoryLayout.size(ofValue: TwoIntsClass())
MemoryLayout.size(ofValue: FourIntsClass())
Fih qtu Llehckoecb. Cejk bza bsciq xaka e mehea at oimvr.
Xuv qacifofge vfnaj, nbi duqiowsi imjobd il cqo mako fexa ev Uft. Lgu jeyyijlg ez bdu zoyievno il fwi algxapj oq o nerujb bexiyuuy mwimo vda efquil rixuo al mzeluk. Os soaqv’d xillac job hitx loqawl wki dudoe ilfijc or itovd, lhe takokipfi ox epyohw iijpf hih o 54-jin LJO, uv puix jut u 40-fot SGU.
Bpx kdi duvu kep o zyodn vopc to yiyiecvot:
class EmptyClass {}
MemoryLayout.size(ofValue: EmptyClass())
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.