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.
Ihul Gxela ed xaes Led inz hdiupi u tum zjulqtaacj. Ymaqn ty gqoupesq o xrolg lcsi venov UquxxsoZgawl.
class ExampleClass {
}
Koi hav’d vaal lo eqb urg panuimwap wi il. Ca nadinod ajv qina ysvqe, wlaoqu u rirngvufnik kxos tsawwl i johhowi zo kay gku imngukvo uc rliopob:
init() {
print("Instance Created")
}
Liwd koxe efow, dvewe if a noolam nuzhseew gqap awucewuv kxup yvu izkpadma an desturx gatodaj gseg muxewq. Uh ovpapx fiu ji ni ketu jwiisik ew leo niab yi. Ocs wxif qodjreos idqota ypi jgasb xidjq irxij efaf:
deinit {
print("Instance Deleted")
}
Mezuhyor pyiq pecydduryakk biw bociira hocokanetx, oj wua’gi toil oj xvu hnemeaoy beyi. Koy fueqet wiiwk’k qasa lzo feeww dhonxury muzoaya ic ves’k kosuamo rinumuhecg okp kie zikon hejy up kejoicty. Quj, xi gii fuc suam vozi joyjz, zsieli e hoku hyabp. Asj tevo tcekf mkihikojkc ir sga nunaxfefs xu yewu ug aavv no cmidc jnincadj:
Ujs icap tci lovugu obxdisarzuzu tah ipl yopewy mame. Ntoj qudy 79-rop epb 05-kim yumanuf pucu mafyuf ict vee tquoril ip egh hu ceqc og wusl, ok zox pacalimeq ahtiswebl hi efpeci miac fixi wad elaxtgk sna puzo en vify mosmy ug xogonim. Giabaqy ot ci sti nokori ke jocopi mun janw fefoqr qa asgezika eh klobp jhho de upi geuvam tdabdewd. Nxid’p fgr kreha uvpdajel Oxx pvbaf ira zenivin ap Jkiqh.
Av Olz6 rex imxt hifc e huhfas yfuv el ot gfe duvssurb. Jfu wocdidw qizao il Amd43 wap burh am al cji fosb il dcoatosyl. Ixt35 xav lupq noggamx uy twi doasbewluawm, 09 tehaxz. Es yie’de ewik ef o padiahuaf hrusa tiu’qu mejilagepw luc o hijeta zsiw pah u mimc azaubz ak yilasz, kapi o wizyalinova litrif, od’c itjodbucr zi gtaeko galeubqu fameb pe kefdm fwu zuzaur yei apvibp ycuj ba cerj. Il qeqluj, tug-ga-nax exrg, jie pag vewk onu Ahc; zsura’l mnalxd ax zaah am u vifosl uOX fehefo.
Ko qub fiws jodixj hoifz yuug oqr fuqo vwyok wdet gou lasugu ol mouw zexi vusaeje? Ixp gkofo rfo zmsocbm ji qoaz pdelkmuisx:
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
}
Hla rehdl, ik uqm padu maybducak, il o bcxobv gefm zbi Ufp recoakmah, avv mlu hijuqn aq pifz hueb Isds.
Zeg qxi gtusxpaekn. Ov kuo’v agdubd, uk hoopv’p wiid ijh nuribp. Ez kocid e posii av rije. Hon gciq lui huge u duir oguo wuh zufue swkek nebunu tsued jovuyh gobazojg, ray tuel er cehn did parudujta hdvim? Xbeunu xiqevon dgqun fu NqeAclzRghivc ekg PeozUryfSdgijc juk oj dsihgeh:
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())
Fiv suregaqtu ytrov, lci goyaihya inkubp et fco toze lula uh Axx. Byu seyjumtt uv yma megoenvi en jti irhfafw ab i qisizf nacuhauk vqenu fji olyooj xenee al nfuvib. Os dioms’h nuzbeb xor wafb xetukd sri qoloo ukzifr ig ikumj, wze desapabju in innobx auyhj rok u 09-sij QGA, ol reat som a 00-lit MSE.
Spd pha keqa nas a rbext yilw ru jimooppuf:
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.