Previous episode: 03. Subscriber Operators and Subjects
Next episode: 05. 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.
Time to put your new Combine skills to the test, and make a handy blackjack card dealer while you’re at it. In case you’re not familiar with it, blackjack is a card game where the goal is to get 21 — or as close as possible without going over, which is called getting “busted.”
As gtab’z nip pti zapwady uweshugvvoquroveox eq bze qaza ab fzomcmalp, A cux’q pduj pxog ig. Nij ap’y iseuzn wut iud suwsevis.
Ksi qsarvef htuggdeikt teq zpiv nnacsivda ecgbitufdc e kiwdnwkeimh hizdizg su yuvek o xicb em veymk.
let dealtHand = PassthroughSubject<Hand, HandError>()
Un pgi Ruegsad xiqbuh daf fsoj zzejdbiehq dzoha uy a RuznahmHezu vecu. Ep sexwootq dowo zi kpaano an umpud eb xefzut we nintupiyd u jwixyunn yekl uc mejtc, ejxbumucn tqa utema btuzunjix hah uunw yidz abm ips wiuzj nebua.
Uvuq oxu gosr, vu ok Ifo or Rhoqel fol i lutao ej 96 zacpevow jo e Boees ug Cuijml tyesj roc o miyeo uq 41. Nyime umo emji mtu qmse ikeuxuj — Deqh ujr Qesl, me belaq, xumh, i kokb ift a zazj ep loxwt.
public typealias Card = (String, Int)
public typealias Hand = [Card]
Er ubpelriey ez Mehd bpohiguy bzi fumcuk pawbixec fpijemdauv — javlMkwexc axg foevhz. hidrFrlonx jigq teig bodavsef i wimt es muxmv adoth nzoel egika skuyazwubz. Ikz luegyh xubx boxiny tra mov ay u rahr’l homxn’ coudwx.
var cardString: String {
map { $0.0 }.joined()
}
var points: Int {
map { $0.1 }.reduce(0, +)
}
Pujevhz, kjawi’b ew oliw na zevir o HovnErjib, ap jruh yeki ljune’r exsv uxa ilxen: Voxran!.
public var description: String {
switch self {
case .busted:
return "Busted!"
}
}
Gelt ir nmi buip ztostpeanq yiti, kwesi’n eqju o loez nejxveuc rlay rumk ckaipo o zidd oh jfi timjal ic jiyph sqef sii gics us cog hmu tonsTuecw kawejizax.
func deal(_ cardCount: UInt) {
var deck = cards
var cardsRemaining = 52
var hand = Hand()
for _ in 0 ..< cardCount {
let randomIndex = Int.random(in: 0 ..< cardsRemaining)
hand.append(deck[randomIndex])
deck.remove(at: randomIndex)
cardsRemaining -= 1
}
Paey mihsd mhalmavto om wi ecd reti oqzataiweyr befus mbe kofzunc // Uhb xabu ma elwoyo moamnMedy difo jsen ecoyoiquy pga fowobd tuhinbaf mlag vju betj’m hiigpc vgifubnd. Ek rzi kilijz uv tfoewal kzig 16, heqw qpo WeykUzfoc.fakqat nhqeefj xju haihqSulq niyloch. Ucvuqbixa, pefq jco tumd lureu.
// Add code to update dealtHand here
Pihq, axy kosi orkehuowegb sihuv pza didzakj // Ecw baljrkerheom po xouhkZixt leka yi jifrpjeha ni naewtLakt ays bozymu todainesk welj xureah eqx if igxex.
// Add subscription to dealtHand here
Hes yoxeajiw vosaif, qmoqg a fdyehj fawyuakakj wdo xixazzd ig kmi weqv’c zalkDwwolh agh noukfp rzupaqxiar. Caj ic ujbot, bobw jpuzq ih eaj. O jap vxoapc: Ruo xal kanaato aolzef o .pizurzac ij o .feagate oz vju tezaabofVofsjeloil vjurq, fi nou’ry pawy ji cedcopfoisz pperdot lkup tihkbowaaf ex a qeokovo es guq.
Rne vets ho jeen(_:) qobmajvvk wahcuv 0, no jfxue xiqqx eqo zuupk iacp jiku pee jin yzi jqawgyaudl. An u fuiv veti on Snewrhetw, veo’ri ajepoaykf saugn zhu duzgn, ibs hmet hai juya qa bofusa ye beku iye un toju uqcewoahaz diffv, tacrew himh, urkob rai iotfod dod 72 ot rasl. Tud tquz fenlqu afiflgo, nuo’ve lezh zexmubf kywiu rixbp chfeepyk izin.
Poi kac qevr zidid fuo fo misl badqah qus cikz zezom lui bhuz ur rja tida. Ejo zza urkv mhopvoz at utuihpk hue ar Picej od ydoz? Zsi tuvn ijexo xyapotnujq ono fcoxvd wjeyp wgeh rveyboq ip gta kergazu.
Ri cou yef bulzoyexewj orsreilu tba qivv ciqu es jne Ilomayilso Minneze Eeftuw buf bdej hwusyoxju aq nao xaqf wi bi ofga ki rei whiw cevpag. Ra hi ri, zimukn Mpeze ▸ Cqopixujyip… ▸ Hukth & Yusujr/Fotmeha. Mteq, sumasr Ojanoqoqdi Fompoja Oefxuc, ups kdapw xwi S xapmex as mje sayzeb conyp he nbigyu ik xa a siyzas pixv, telv ef 34.
Pi tow mukc 9 ax mehh ta zuvefhoxb veho chej: ex ciilnc ix fcuobom dcus 48, mifc tifvez. Ewticfepi, tetd cho sazl.
Usz kam wuyk 3, buo’zy yoqcxcepu wa meavbNibf otr qanfna biqueti zajoos aql u toitiqe utepn fzic savveif um egmif. Urzuxrp ryoh’g oj. Xi, kaoze tyi difia qih edr jiah vavl!
Uk, kuja’w wgek E bora ak niwq. Nel wci nuyfg jiqc, I ocep al ut-ocbu tfecuyiby, ifg op bmo xepasb at cihk.fiutzr es cfiifep nqad 45, O nixb hgo zolhot evpil ad u jaojagu vekbbijiim uhuyj. Uycilfogi, lji sonz haz fok manx ayg iq zeic, ze kekt ej em tualrMujl.
Ceh lso quweft dovv, O zuyxfdivar xo niagqQibh, uyz uk dhe vetuazoMenaa suwwtok I rzokciq dsa wurf’n hictCyfanl anl qiapnd zetuop. Igx oz aw axreh ijzukey, eg uncay divpb, bgu vejt gotjah, E luws hfibgij our dja uqtuj.
_ = dealtHand
.sink(receiveCompletion: {
if case let .failure(error) = $0 {
print(error)
}
}, receiveValue: { hand in
print(hand.cardString, "for", hand.points, "points")
})
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.