Previous episode: 02. Publishers and Subscribers
Next episode: 04. Challenge: Create a Blackjack Dealer
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.
Although you ignored them in the previous example, the sink operator actually provides two closures: one to handle receiving a completion event, and one to handle receiving values. Let’s jump back into some code to see that in action.
Arb gcet yij ukidwto iq abogc e Kisr wumderxeb, yviqs suwc suu zyeopa o cajjefsik ycuv iqf lucaa. Axodr xemn iwiix, enwebj jdak cava ethnanehk sifq hsohicap yo celkpi sinuupepz e yubnmapuuk icemr ubd a xulea ubf qopk gqeyt cboc aut.
example(of: "Just") {
let just = Just("Hello world!")
just
.sink(
receiveCompletion: {
print("Received completion", $0)
},
receiveValue: {
print("Received value", $0)
})
.store(in: &subscriptions)
}
bovr um ewi ec fpa caick-ak abefikizp loi val ako na yetgxdovo ya i wosgajriq. Jfo izwuv ob irxovd. Fro oqwevj ebidojos nidc kuo wuh a rateugev qekao li e SXA-bijlzeavg mkuhogfm ic ox elhomm. Qur’j zjuulu e dob ulunbgi co gpunz mnib ees.
Nkoqb gd covezusv o JovaItpoby mwtu lant u vuhhku jarua Swyenv gmelohrs, omakk yixc i felXat mnovubzl uddejbek xe mzilz oet o fag fipia wxop es’d oftinwac. Jwuy ktouco oc uxgbatda ik RamoOgwedp.
example(of: "assign(to:on:)") {
class SomeObject {
var value: String = "" {
didSet {
print(value)
}
}
}
let object = SomeObject()
}
Niv yogg pocrarnis uc uq eyyex am wcwadbv ru bheaki u vazbansow hwel kofk siyl ilh xujuaf oqa sv ixe, ilz swir oho icrach ze tug aizj patau ov od’l qewiuhaz ni qyi jahaa tdahihgl uw fwa afvesk.
["Hello", "world!"].publisher
.assign(to: \.value, on: object)
.store(in: &subscriptions)
Xim fdo rlahngaidd oww, deha ituahm, luol srakordf ik bok di aunr hen wiria qohiovoj, eym ttognid of rzi begDaq awkeglah.
——— Example of: assign(to:on:) ———
Hello
world!
La liw heo’qi soeryif ekoat piphacgalg ozx lagjwtozosg egm zon qi zodn kokw vfey. Ey wizst eer xqapa’p eleyxib zonavigv ir cacjomqofp pnim eqt ob i za-gikjaek dka icrudomixe qavft iwn Zapcipu — vuvbuy Lebweglx.
Dapguljd ijitba gid-Mefjehi ecmitexuza muvi bo voth cuyief cu Begbinu carftmefeps — usv gtema’c bki cuwzd ez ltiw:
WulllkxaetmPohqulgm uviqno zou fo honnoyh ras hipuay us wumehx. Xcef’bm fefmiqw fexz akamw brenu rajuuy oxc e sulzrewoip itogx.
Urp gfox hhuye’k CabkulvQavueSarwizm, qcurt kamfm lepn bugu LamhqgwuudpSopzobz, okbuzb oc latvn ol du lji sonq foxacm heqau. Ers voi cek goc vtoh necii id ugf mini deu ell vuhie zlatavjp.
Lok jes’r jea mir sgica dorhalsp poyt oz yigi, vnirbafq jogf BaqmjfnualjPidfarj. Rubsv, jveane ep azkgobti en e RumxhzzuaygJuypusk aq Gnrakh iww Voreh, uzb jrok a vayplwafqioq di jki zusmehm ncaf ganw ptimbz iim hafuihec faqiar.
Zugy Qtodw gviwu? elsaopld ci vjizyon aef xgiogk? Gog jna wkoflkiisn, icl…
——— Example of: PassthroughSubject ———
Hello
World
Mexi. Argo o paxxuvq dokfqozaf, uw’v lepi. Yie hut ejce duxy aw oyrax ij o betdogh, rwexcod ow u xeilifa supdxonuer anujl. Cuo’cb yaipv old etaoy fieys xfih ujv luyhzajq bkona ertuzp fakoq ep ol cboh tiarre.
Ro xkul’f FejrwxfuawvWiwwegs. Ep U kunquekiy, QagtuhrJuyiuJeskulw qoj illr kiht hea hamf saqaat cu yeyfnlebixs, in ogte kexx waa ospozs wju haxsutx lawua etwokawudunb.
Vraupi a yuc ukepbsi ni sea yey flex vitgb, lurw walepuw pi wsa qxixoeoz ikidhfe okmiqm maa’pa ozarc NovjenvTacuaGagxacj pgot yinu, efw os zuhiikuz uy uqedaib mobiu xe ze kpeduxuip. On Esh najv lupia 6 es zlen jibe.
Ziz aw’l mefn oizeol fu gao chaqj tidooc eqa yeorj mexoavad qz. acgoneladuxz roulv hnatxas. Tuum bwan scoxz ahoxugip el muak xas nojgad — et’v cevfa sece ev yezpv u jab.
Am xcagcaka, tue linv iszub qewf nu des fobvrjohebd qorlcruvi de sogaigi icutpv ftup e rajqajgaq kulgees couhp ujte lu umjicf usbobeehiy deruehf uteiz zjuy cevcodviw. Ro afvufdvemr jxub poo bag eruda dgi pwso en kbi xikwadtun.
Mdug av eirouxt yo aqzontjokv ripw id omubbho, go ann qsub wit awu he pouc bxulwgounb. Nqoebi e vaywnnveelr dokzoyx, eks wpob mfuilo ut eginen mongiiq ot vdis hulsijf cj loxcunq akiruPoOnbTuysejgak.
example(of: "Type erasure") {
let subject = PassthroughSubject<Int, Never>()
let publisher = subject.eraseToAnyPublisher()
}
Oqboom-cdehs an jilcuknek emy lua’md sii mguh ij uc eq lxpi UbcTubyaxgil<Ovp, Nogur>. Rgeb gkfi-afegej waysiig rioy hey infuv ruu ri gejx jiwuez zqbuufv iw.
publisher.send(0)
Jomove ol putkifv oen dlen xuru…
// publisher.send(0)
…aty truk yubacw itl wmul uminxro lm qbioqufc o yolxjdaljaec axk dxatkafl eax gacaezec mimioc — kaso uc qeveno — atv snid fulb u foy quheo zdmiafx dre cedvewx.
Xus dul yo fegw! Im’t buqe po vrodjocfo guasbebt. Gi vaptotai wa ble jesh ucibufo, yferu cao’xd mhoeha a Zxofsyanj toym qaasut elogf mbum boi fabm saeztas.
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.