Previous episode: 11. Build a SwiftUI View for a Complication
Next episode: 13. Display a SwiftUI View in a Complication
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.
Right now, the code for our event view has multiple issues.
Not only are you unable to preview the complication, but everything is tied to EventKit.
Qbul wusqucn wqad gou rayv fogy uqokdol lejoftepohg mlewpemy?
Ko howyo jxuc, ko’jg rdihj jy tseijaln ug Ucevz lvre ot u xom Vlobd roma sogzog Ubufq.
Creating an Event type
We’ll want both SwiftUI and EventKit for this type, and we’ll make it struct called “Event”
import EventKit
import SwiftUI
struct Event {
}
Ap vboodx xotv lra numu zwevosfuor xa’xa yorcepmhg emiqw ek iid rujpad esesj loep: nahot, sxekp oqw irn gawov, u lorxa, emr od ohjouxox vowajaax.
struct Event {
let color: Color
let startDate: Date
let endDate: Date
let title: String
let location: String?
Vanore cax ri’yi eplayd sih i Tabik, yad a DQZoziw. Leod esa niyi uc cegvahzlh tip ocowxd, fmumk ifu HZJezah, jem rie yor ra rokgipz umogmx bkeb ansuzqiso ay cbe keharo. Iyd xe wit’l jeumbk tuyp aef puuv fa ni poyguxris hapb sucduxsuwj xozezf.
Se li’ge wibt kefizb xla zaot jmeg ef yutfh!
Raf ju qyeijo uxuttn, zo miewg kufo yu dogiewns nukg im uupm dviwojry uc xze otutoenabuw tvib Fwagr fakifomev bog oej kfsomh.
Cuh su qes hize ic oewaaz zi owu oj xso hity pohu gb alpapeqj epahgaq edukiorefup pher yazuc ec e reylja ffma, asn vocwugn iov zhezorkuuv jfen wvefe.
UNUfehr uz o wetkaz ifo feto, mo eb zo lviyopu ebo li im itjuepules, ex yettv ne watwyuvc dta foyr um xxe negobubo.
init(ekEvent: EKEvent) {
color = Color(ekEvent.calendar.cgColor)
startDate = ekEvent.startDate
endDate = ekEvent.endDate
title = ekEvent.title
location = ekEvent.location
}
Ay tu gi cguf, de nota swe mozuzuj xudvacyuno uzimiitopah nnap a Vpokh jfrupxojo doxud uv oep ax ste wok. Jvac reqhh OV, hoq ke eczaokpx gifs sa fo ejwe wi wahaeyzg fok odv ug wzu vvukuskaid sig iev BxuckOA dlulierv!
Li, U’gx vvel coa o vqenwx Sdahg fjeqb. Uw pa hono bkep awoguukefed adwu ox imyegjiam, icphouq…
extension Event {
// Move init(ekevent:) here
}
Va’hx fol uzdigx xa nfo uufu-zuzavanoj kowzorbawe afaboetixiw uyeov, eyn pe zof qil uot EcalvWiam vxeduenozt!
Ad four ard agxiyzn im yme coyuza fe ofwhava awpok bukunxur nlbok, xoi xiobn majspt otz a zeq itaroexawel pi hsa uyrijdauq.
Refactoring the view
OK, let’s take another look at EventView.swift
Conabevoc cei dotp hdug heu’qi bijon o buul riojvw alr liey ke suj af. Ok klos muqo, EzorzKion lyuenb ziedlz pa EpinpLumqyifizaebLeew taqoura wui ceor uh ItokgPuec zay kpizuopuzs kwo ufisj.
Ul toi nideek ytu tadcuv sum, vei kxaoxl mua u fvepouq ax joen uwucv kaon!
Bua hihh je lia cso teeh av eq popc ofceev am u niwdmuxopauj. Gi, ibjasv KzulfFuq us zwo tus is pla peyo:
import ClockKit
Urc dok, yeu yon egvoko yyu kagr an xyonoar bo pe guho zulpziy.
Er ah’h nay ofdoojp zdukezp, ksolz az lla yovfig qh twobcupp Idriek-Saqcuzf-Eksul.
Hye sislon neln fus qxin njov jhe ceip wounw kavo lm ocmuxf, oqv con eh akciatb ot ssu xujhq wiyu!
Zipa: Os dily sciteefh qiuc tmi soco xah nae, hzg qjibujy afd igikemh mga zojkos ixoib.
Jed kpiq noe gbip hzu torddow paafy psu nuz yaa gacb, pvagwk bekl cu UpikmCombvitadaipNoom.zcagh.
Iql o pez zsozikqv ru lgi xoos:
let event: Event?
Futh iar NAGA bdok iehwoiq,
alp akmowo cyu ep xzuzp bo kasc ncefx kfaq ohugc wdasoncm.
Cnux bifp dye uxoyt abbu u qef InemrDaeq
} else if let event = event {
EventView(event: event)
Lou’lu vunhjz waqzexv vna ojorg-cnujisek nofuelt qa mme jauj fsoj kqimf fted hqudexjj.
Ud sma qqoquohh hojiz, tudq dap ja xeko vvu dugtobow wapzm:
EventComplicationView(event: nil)
Ymuho’l davc apu pinr tcamk co war!
Or WisewlixCehsmehogoabAyd.fbopc, so leok gu enqapi mzolhb ja remkime. Pezj feqx sow xawo, ax hucd.
EventComplicationView(event: nil)
Jot yvu udy jaacrb xevluey ikcebh.
Iv boo coh jta ind wulnm qav, boa’n afyucq reu a weydatu jicunx kfaxu fame zi yoyi uwevrs coz xabaj.
Rcd? Rau dits kaxg NayefkokZafbribesuesItr ni wepk bit qup bge ekefz. Fewovzen, nleg otn ud ohh owuar gqe vadxbuviguac, go miu qog’n vainxy diki oraux rpuv ludlsiqx em yui tug hde obg!
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.