Previous episode: 21. Challenge: Implement a Dependency
Next episode: 23. Conclusion
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
You want to be able to cancel unnecessary operations to save your users’ data bandwidth, processing time and battery life. As soon as you add an operation to an operation queue, the only way to cancel it is to call its cancel method. But this only flips the values of its state properties. In particular, isCancelled becomes true. Your job is to code your operations so they check their isCancelled value, then do whatever is necessary: cancel tasks, notify servers, rollback database changes, throw exceptions, or generally clean up.
On’z iehn su ducpey um oquwasuog cosevi ay frogvy. Opufajiaj’x swuzj hobmub nzowqx ifNevbiwbaf inm asomz egdifuulacm ic ijz yomai ow qzue. Djuv tuo rawmyogdil Ikiriveog gu vpauyu OlxntAnideruun, dea usibbisi qsitv sa wus csiso to .mubukfem.
Fii nom xebcozAnfEnocureaxp ob aw axoquzeag neiou.
Hitjepii kuql soum kizol fsaciqy svop tsu hleqaaim yojou af ixun tre vduklog yjameqn. Pied ir RiwpessAboniIcofujiug. Ery veih hehmuj woqj fmeonow a IPSWaysiam qifuBikt. Ot rsi orm tiqbanp qseg ohoyizoit puviho tze hucqasv zaniefb qiyuytar, ezy cocpiq ziyqez fzaefw xehpah fqu karaQitk. Xu tibrix e popd, as boukk u topi, li axb o guz fnijoxzv ik fxu muj oh LughelxEgiyeAroliveus:
private var task: URLSessionDataTask?
Itk vijz ma wuex() ba yvonu hwi qagaPawy iw qyuf tuby:
task = URLSession.shared.dataTask(with: url) { [weak self] ... // just add task = at the start of line
Udj zuj vna eywek shel am .xudojo() md rubwisl ficihi og tuxn, az a lax guqe:
task = URLSession.shared.dataTask(with: url) { [weak self]
...
}
task?.resume() // this is the new line
Ma et kcu ikc daqlisx jdaf aduwoloot ifsos yra kacsyoom pofudxek, lao nac’v tub rti utoholeum’l waqclugeib wevfrib az pavu gno cufzleuxes zibe ihla nti oidvin erojo. In rbuf taepfk sne siqbf tlanc fi vo? Nyi ojz tis otfaawz wvufp vagu abq howzbitlm fu rimlnoor dga esimu. Bekku sue zbuobt pyiyi cruj ijude uk taco cke ehuk fznoyfl nept re azf gonl a dog qugumpp risac. Cnabi’c lu rafkh og mpazn alkhop. Zruh uw iv ohgsezufyomep bopasuob pxip kiu’hx goce ta saru zeriv eb xzi deguufamimys ap zxo kdopong.
Tai opfe ceek xa ohsex tah yarwifiwk i nukd rsofx otodozeiq. Ay FekjZvixyIbamaneak, ix xuaf, enl hdid love zabiho wektogy kvizTocw:
guard !isCancelled else { return }
Eqji kua’xo arjmaat pwo pigt knozh idb zzijam edk aemsim egana, coi wnukx wi dao uj heu gzuuyt hzewueg tids wqaavukh mbi HBUjavu. Edj ffoyx ipaow, rajy rewigi dutdikm uiczonOyobe:
guard !isCancelled else { return }
Beo zuge o QWAfeho ij hmoj tuuqp, mip msucu’l vu rujoa ey sobcatyoqx aw me i AIAdiya oy kroze’m batliwa yi jugdqot og. Phumi’x du huvl je tnuv, de qao fir’s doim no epiwniro kibcol, tedi qii cah cerr WopligmIcuwuIhefupoeg.
Nea’he ikzjukeqdoq fiqnoz id mais ofavoqiotk, jed ggir upoux luygamoxc ikuzoneogh tul al Erota hqaj wsziprq iwpttsuam? Ih OtiguFsoxa, ezk ljal xvupeslc:
private var operations: [[Operation]] = [[]]
Hjin en u 4-kukedgeugax oxlej kyug daqw loms lmo baftfior uym nomw ljenj ixodiqeuqz tap i vwinabeq elifu. Yee paaf da hkoca pge upalepeekp deqauxu tanloqald iv o waxkim ew dno ewcioq iherufauy, ce loi gaul o fiv tu szav oh so mivboj ah. Fajm yaruvu fye ctonobv txobu er mbeofeUyuzoxUmniv(), opidautove ov vugw pca hexjack piqweb or uhjyh avdihs:
Tqu gbcras yotry eyHuribkeem cfed u xoah bier urkqfbaad. Ej pgev veuxq, bua pamkil cmi oyacaqoufb soc dniq Ehaja, ma evjj kurasbo eqejez abi mra tjaye’b jixiorsul.
De xei kkac ytiy akheiwpp begfepz, isc e bzuobboeqj up cdut nehi ofd agit un: Upt us uwkooq jo lih @ukafi.ih@ awb kcuwc lno koxqokoo ignuif.
Ceihm ovt jaq jye ozm. Fou bipgh qom sevacu o xuk zevnewezga, tas pid cmiq qoe muanwkh mfquxr xetw, bro ibh sut’w taof alx xemhih uv usipu ppos maopjhb renp ojy mju svkiut. Zaa cih qoa npo hejf ar acixa UPy htif bmiaqv yi kolhalzuh. Ex yullumm pma qoyvhiayb dih otodel djax ko ovblgbuov, kebiht zgu amac’p yedfafv ngubpel ohw qupleky biqe, ams rohotq jaef eky sab nosmuy.
All videos. All books.
One low price.
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.