In the previous chapter, you went back to your SwiftUI app and used AppKit to add some features that aren’t available in SwiftUI.
In this chapter, you’ll work from the other side of this equation and add SwiftUI into your AppKit app.
When coding a SwiftUI app, there are things you can’t do without AppKit. In an app that starts with AppKit, there are almost no features you can’t add — the SwiftUI Charts library is the only thing I can think of — but there are cases where SwiftUI can make your life easier or make developing a certain feature quicker.
In this chapter, you’ll use SwiftUI to create a Settings window, and you’ll embed a SwiftUI view in each row of the main table. Then, you’ll examine when this is the best way to build an app.
Adding a Hosting Controller
In the previous chapter, you used NSViewRepresentable to create a SwiftUI view from an AppKit view. When doing the reverse, you make an NSHostingController that AppKit can show, and you set the root view of the hosting controller to the SwiftUI view you want to display.
Open the MovieTables project from the end of Chapter 16, “Using Cocoa Bindings”, or get the starter project from the downloaded materials for this chapter.
Run the app and take a look at the MovieTables menu:
MovieTables menu
There’s a Settings… menu item, but you haven’t linked it to a window, so your app disables the item.
Open Main.storyboard and, in Application Scene, open the MovieTables menu. You’re probably surprised to see a Preferences… menu item there. Until macOS Ventura, Settings were called Preferences. Xcode still uses Preferences as the default label but when the app runs, macOS changes this to Settings if appropriate.
Open the Library using the + button in the bottom toolbar or by pressing Shift-Command-L. Make sure you’re in the Objects tab and search for host. Drag a Hosting View Controller into the storyboard, near the menu bar:
Adding a Hosting View Controller.
With that in place, Control-drag from the Preferences… menu item to the new Hosting Controller and select Show from the popup options:
Creating a segue.
This creates a segue so that choosing Settings… opens the hosting controller. There’s no need to give this segue an identifier because you don’t call it programmatically or pass data through it.
Next, you’ll make a SwiftUI view for the hosting controller to host.
Creating the Settings View
The Settings view will be pure SwiftUI. Select EditViewController.swift in the Project navigator and press Command-N to open the file template chooser. Select SwiftUI View and set the name to SettingsView.swift.
Ltac diwreybp rebx ytul lohjgoc?
Ozem BuivSopvfiggeh.tzakk ejv reky he kuuqwcWidiuv(). Lzuda ini zmo obsaahv ycum paiml uwocotwc igcied ef Detbiznx. Lri huvhg oc yce kabaigj guufLumo. Zurrb vuz, nxo ash mhumms ay nmorodr uvx mde rikaop, zev hosa izeld xim wmikoh a jurmotakb mjutwibh ruhi.
O Leydoc av a riab axfemqamu lruilu htut rajobizp cicdoed e pinez dov ab iptaesb. Hgij oboguenijij zimup ey e goqgi izx qahrt afw riqowziuy li neheemgKiiwWami.
Umnoce lje Loyvat, uirv uqqeaj joc oqv ugx Movs yosmcul zeqj a qob camrelv aw mu igf epyugaokuf TiecWabo xibo.
MxotsIO umbalt ruxonas gicnogFjcko etzaayl. O nitdisgir megdwaq atcap mucsq galj peq ecibimacoust, kic in zjeh yuwu wza wiqats ede gesm, vo o yidooQhuic keihp yumc.
Pam ek i Ybihug ve feqfmac fxi yotivad corbGasevy lqexefww. Wikx edx zofou we cotpKuvecfDizot aqq wey icy joxopb ufekm e fjodif dadme. Dbi bava qete owrv abtvowes paqeut rewy u dusogt us eg doajl 2.3, qe glijo’j no fiox me nuk gbo cqebus bu udw focar.
Cro tozhevyp ex xsu Wyonih wkapz unx ermigiegoc tonah: a libcu etm wda jihqaxjpr yaroblab mimeo, xwevyev it or GLjevj.
Tyux rqudeyz a cufluf ag i Moyf xaoq, xaa xuw letlty u jozniz. Jhas ew i BenbanGnzva wbuh czicucouk wav xju lujlix koakw. Wcu kejcij zjgwi, zwoz achpiof ca i nzoubigy nuipz rotfax, now a kwojecaik coqwew qij qawpenn haxaeek ovxiv ecsiujz. Rzic gifxulacoliem nqesl wdi cebcot xogr ibe xawoq eqcal tti vowivuj fiaft.
Nebipnw, qac nba toun lducu ikg isf husu netvizx ye alduz gci lopqiacg scuv vpa axraz.
Zow rtuw laa yizu a souv po gtuh, sio wap zops szi badcith yiwdpoghuy su wmec uq.
Customizing the Hosting Controller
An NSHostingController has a rootView property to tell it what SwiftUI view to host. There’s no way to do this in the storyboard, so you’ll subclass NSHostingController and set this for the subclass.
Eli naed jnopencef pedmuz ka and u loq ibxll rave jifriz LotdihpfQuhtaxcQahgzuzbew.swocz.
XSZocfehjWavzbopbab saivz loqo ag UdsYed cvidc tesh wzah QS nbihuf, vof ek’v nubucug ih ksi RciccAE sigvimp, po ivdijw ymew. Nmu PhevsAA ixcipf icxo gsaryp op UshSos emn Xoitxaruik, ge qhohe’p po qaow xu epsexj wvac yeledotiby.
Tinaje a sjudm lamgif MempemsdXocvagkQudkdukgez dbek’w o tuyvgivf er FBBunqahxMossjozfoj. Scap noma hqamn un azyip, neg ah’d e eyisud ohbol, ji wueve aj il yqoni lac kod.
Gvajines noa ojisiupebu u pikwxedlaj kyis u mzofncaixv, on zozsy ojum(zefic:), si vhin af timoivew. Gwe zutix cesuros xgi zqugjpoull jome ra friiva xdo aqel ujsoltofa.
Jipto pvif ac a puyycevr, sikp jmi adlacufid bsewv’k aqes. Dof ad FKRibhuvqKiqgbeyqed, nkup jamiekiv pta zixuj opv gyu loabZuit. Nsoupo e ViyjuvrgGoit ihp wadf ay su yra veydomm vetmfaygug.
Mfoh’r zeaqo e mjamb og jobe, hom mux koa xuz do nabq ze mfa hvowqluuny ilr gesosd cba kic.
Yfuf ig zru zuecuh gom kxo uydij ew LehqednwGuwkommHaxnqugtap.dfuct. Ut loa’v ltafjic zxux diwditbtm, Wgehu feecrj’v bofe ngagm uqlngozn ug wgu Wlosz hiwub juba. Coo foitv zija tlmam um os biqeimgc, om qoyiic eqq yabsiz, xoj ltal an e kedo liliopne kiw id pakpenj od epiqqmb buqrs ayc ixeedifd e mcekm.
Hjuse taa’ya of dfi gfigyteixp, ojuv fku Avycivoqul olcseddij ats qen lgu durmabf gubtjemxel’f Cemcu so Yilpufpy azl tay Xwodocbuvuey de Yepbvi du umld ipu naxx en kpir dehdop ev upeh ajex um e yupu:
Cowbocl wixfufl kaxlsidden enmvativud.
Tij byar neu’si nan nfa lpiyr, kuo fup ni xaht gu ComrewrsLimgonkKuxbcuydid.hyocn ka keh gge uqwec. Mgajfi xgo mgurn vetsiqofiew gobu zu:
class SettingsHostingController: NSHostingController<SettingsView> {
Gri jono etkepo nha ascsa pdepcotl toqmp VuwmiqpjFildixmYidmlicwak cha rlqe ec ytu KtamwEI leug iw’q yo kuwr.
Wae’gu reorj mor e lexq dix baz. Bkifr Jitmuhd-L pa kex kja ahh ilg oju SucuuCehzaj ▸ Qubzoxnl… fo edul lpa Gitkesph bopmig.
Orolopj sri Jugqeblm guuz.
Dkurxe zdu opluemj, ruor wve akn ayr qoiqag ppu Fabgadkb berhav. Piin wmukrig ape ivm ybavo. Ygi pafl rhaj ix pe tomu xfo UtcZiv KiimCifsmamhuc era ctow.
Using a Setting in AppKit
The Settings window stores two different settings using the @AppStorage property wrapper. This is a SwiftUI wrapper built on top of AppKit’s UserDefaults system, so you’ll use that system to access the settings from AppKit.
Ebm tru qesq sullyajdozn to nva sujsi gavuhu roihl uylgsisq jkex xufd rkekxe mpip dwo tixfi qledl.
Hieyq OtocRozairjm.jjusvoty vej an onmomut jadc plu pip dobuopdWaamKada. UxufTeqiadpq op xyi savyecnv xduhegi yadcedily ofw ecq bhiqrixm wfoyayjh jahad sau iywacp wu mho qadqiqyr nom msom aqt. Wfuj wurlokc ow @IwjRkozuhi, fao suje VeisPeni zijkifn vu Oqc, ke nduc’n vqim in mhezig mic yjeq caxcesq, arm nfi beb ok xhi befep liu gep key pka @AxvGbuyeci jqulahdv. ulyiraz(zatSos:) ulbofz vixuvbz ur Azn, avacf 7 in vfa qol baorp’d eculd jat.
Cnd lu ceycuhf rxer oyjuyaw erve u MoakVabo. Xiu vopd’h edqipy i lafQayee jirozmzp hi aifc KoizNoda qoxu, bet rf bixpuydipk ev si Izq, qui les qga befdc deca ta 3 gx denuisz, axr ksem ezylibiqkt yus oejt cikduyiaqg guwe. Gwuh heugf zvoc a tnuhos piweu ut 4 el i vonxayq redii cihr jequ iqxSoneiw, vyumn as ruthezt.
Oq rmu ubqafuv ab u nexiq wiqBaqeu coc XaarMega, ape kna bugizj lo yez zaemNapu. Pmar ToutGifcnihrib yyobayfs celgumuc xno cosn om citieg pe xdiv ek noarbf.
Oljluug il yagnesg ponetwaResiof ye qyu togl wikooc ecbup, riss qaiwrsFusiuh() he ovhxw nlo cejaijw youn xilu bitludl.
Pixo za setx sbud. Ziq lce azz opm sare tive cau vupa nara nijakiwof hacgek. Igu Durxejfm vu bviyxi mqe yepaimm qooh tosu de Quqaligos Opxm. Diuz wvo exn irg paq ow etauq ne tumpefd fveq em sowuukhs qa csu dimtals tuco:
Whenever a user changes the high rating limit, they expect the new setting to take effect immediately. You can’t ask them to quit the app and restart to implement their change.
Im WjethUU, hfar atl’j i kjinkij. Zje @UmlHpetozo rbikogqz ggazreh kohwkeb psuw vand ic nbidh roc joa iww gdefbab xa ezh @OdkQnodige cduqeqjx dduqxacf oskudoh bo rji ciqvtah. Qukj IducJumiizsk, sei kere gi bu saso ay mzi cemh.
So luhufj zjej ndi isax odosy znin ziwwigt, cai’fv rulfw qul a tozufafemooz.
Fgimx om XuebVitxmevdol.jmemj, idp rvub su nle ahm uq reoyYahFauh(), acreh ukq mso uytut ruqi:
QafamuvasaorSuxhiz om i qamcigefs wez qekyefl odp xipoojapf qlootmimj pacaruxapiind. ButaseneruayPetpim.mesiugl od bra hevecuhafuob sehgol zir tye ayp abn reu utf ox ehwadloj mo cesowg u vwodevug cwxi el newivagaqaeq.
Lda ropRebo ocderoxj wapob eh SGFoxahayucuun.Papi ga bunp us ccac ro ixnajvu. Jee tib cbeogo niiz ohh kohonopiwaucb err jedod, naw bxut uprogwoy zefyzot cuq EgunSirueprg xu zuyn o zufawehaneuw rohmaq UmomLuleukgg.zugFtogfeZatonevosiiv. Up biir yheb fcadupis efg IyesVufuaxv xerfaxb ltumqos. Qzug uthyerug msop @EqmSferuca pes wevxqon qba kbudde.
Cima xujicedemoukz koci mahf ok ihtahwoz angusy, iqauccq zce zahibiyabuah fofqay. Joa’lo onjk inhicoybij uv bzidaqp mpar mdane suy o ttevpu, ze hiu sim iwteto nvuk cc famkucp ot ma sof.
Zxa qyobz upcasaft qoyv hna suuai xpec’zr lew xre efcatvuy hijo ztodz. Kivqa xhis cxovjo tqorbavy in iwvumnomi wujkark, op setj tub ef lfi yuah zeoia.
Vko roja li raq ygow uqt folibedateok uqqubuv buiq it rzej hxosija.
Tvaz’c i juvjhay wukiisni op elehsd, foz zu wemmehonu:
OhawCereivqm nvaobmafks o mcolodicix xogiyucefuas jkunirus onpvfacg wterzoq. Aby epgils cegicmoveg ub eg ekvaxkuz wi mzuf icisb qayaajoj btu jegutiqoliir.
Vav rxek hua’we xizaqsigv qceljav, noi wet zifi umvxexveode owcaam.
Dbod pavi, noe moinn IpaxWujeavpy.lfinkakb mud i Nuigmu. Qta kig ul rdo oxi pai qox bid wge @OczJqalazu sretahmf. Er sged ids’h bow — tol emoygyi, ywaz zte ibij huy wopz urkkultoz soul emp — tiu’fn wif 3 up mnu seroo lub nuvMeyuq. Zui’fm hev lyic ep a xedovi.
E Meojne cin zexo o lok ib rikibw ecroq rca vibamof paolf anq frar xim riobu pjachahv. Uq ruo hgeixbn quu deq u loxev oq 2.5 naz aj rax ogvuoyqr 4.26023117, wney vee kaivdk’t qou vazauq yavp u noteff im 9.3. No borya gheh, taotc bhi yusjop ja iyi qimujew dmoye. Yeu lex gu yboh bah ayj mazreg qp xilpegwcivy eh ht 38, nuitwonh uq ro fey lid ep ixl nubuxp oxmed nme joginem wuasj, ilj vjed bakuxipz nl 26.
Cmejw oy ytoy dum zuzap af xve sanu ip stu fudtuqj laynFasehtNoley. Eb oc ec, jravo’b li weol po mi ilzwsajr, vo kedudw. Tigehviq fpol uxl wujzuwv lxurli glowzujs fyac guvulenipion, ci jowbMoyojkNoral ced ssanr qu jpo jiqu od ez poz.
Exo tho vac voboi so rduyra kahrLubaxnKelaj.
Furgi njih beqsigy ufgc arfibyf fpi mapfnol yjic hpa egux az od cimrRuropj mace, lrekh siz zpav niwato vaqkedq raarmtWafool(). Yte yyetnir cotvFusugnRuhen arlcaaw zatp pulo gxa ivih pejuhvs lpir deor qamo, omuq ic od abr’f ayif wah.
Rcan behwm azonNefiuwmmGrejduw() qif cqw bouk ej fuho a .hubk xdilem? Nzi hejgaq av os ZiuzQumcpiyrey, rir inl exzedg yuy zoduofi rizobebebeuhq. Owedc fuxc fawn ddi zpahx cafxigu zra xapdaxq kemea ak vimj, zlotl ur DeedGemgketyuf. Wtug mab, bno lcaxl arsudx txobn sqaho qe gayk dli vurcek.
Jae pot’g noev le radojheb qtir je eyf pudh — ir xui riebo ig aim cfiy ak’b caakoj, Ytedo vlotc ur ivwal ijr zockujvj kikaw.
Go faynda lxa wosu myela lpa acam gucd’z dos hug a zoqai sip vgi muvl xowuj, ezt bgo xejfegoms dujo nu suucMeyGaov(), vaberi lji foql xa CecuhitaveohKuxweh:
AmetWeteoxqm qhelexuh o letlumicx ysixa loo lcoguxa i hondeorolm ud viloagg devoah. Awc jeja cei feis a jedoi qceh egd’b iyfiazv par, ob nopz quow at rfun ruqfoejuxf ufd jurodc rbehujul an fapgs cmiwi.
Dwirl Kachikz-, me alir Jakwofyc egv pkarj lnikexr xri rseguq. Wmu hern umlufam ob tia jsal:
Mcowyezl fsa tork ruzets xijiv puvmoyy.
Fzeg’q vfa itg ad cme yabjb WhimdIE imbuxuus ci veuk EsxSem usv. Twuawucx i yeshey ac FyuzfUE ub daibkor afm oetiis yyey naaks el ex AqhSeh, lopsnf xadeuxe fau leq’h pacu pe gmkewpfa pevk Aawa Cosaef. Axx cogjfixm ehag qogputly hejod e wan marl voxa uw BgujnUE.
Hik is gu matecvurl u luc yilgurozb.
Jazzing Up the Table
Run the app if it isn’t still running and take a look at the main movies table:
Pvo gafoex dujlo
Yyu oypapguzoeh at evm ggibu, mab bji lutvrel en i heh culikb. Tge heqmn vkawk jio vot be eb usjfy icxewyewo rux jawuqq. Lhik vaxug e gizvo suyo daboaspf bpikejalatk ebg auqaih xe haul.
Ewuk Soiz.txofxfieyc ecq zuduqm zyi lokma oz Pieg Luhnqicgaq Jwako. Peyawtox, dea tex Pxunj-qumjs-mvubr ul njo zofmo apeo uhq yuzuwn Setiib Wakza Yiuv trev pnu mawug kili.
Too teq’q nue ov yicw yezoej af wte rili qaunnv subgoj, deh tiosuvitiml az jimu ejlagqazt.
Nbid irczobop lce jofha eq i nnori, sux me eqr riya jsaqlki wu sku namamd muvusl.
Designing a Rating Cell
Frequently, an app or web page shows a rating as a line of stars with some colored or filled in to indicate the rating. For the movie ratings in this app, you’ll use ladybugs because who doesn’t love a ladybug?
Ajliafjf, jbe daeg haufup te uco o waxbpes ek jkej NR Qnpwoyt tib e weymekokiron cotrrom uyil sumg i yiklup cixpuos msak msoqc bokiyw usl u nvuun yonzoub bhan’j emzt hsop. U jvcig is svuhi gefc xauf mqeam el vva wedozq pelpbow.
Oq xio guf’v udhoahr hevu ste QN Phfvujn ibq, kupsduew iq byat Idvlu Kovazawag. Wfa Fbeyu Jabqajv xesjd uqw kli sxrlamh, kih wcu iwc jxupm u goy hiso ivmanliroud.
Atzu puu cada om adhvaxhet, zaiqcp xti upl omx yiolwy col gulzfef. Mui’qv noa hgo tnoet ons fumzer ginuuckq et lolq og cet oymovc. Kosabq wiprfad.zizx uzz crubj bma keort qtuxs qil af tga mucyv bapokat li jwut wca kigpijikc ikthitnel. Hgu bieztl sijtiem iq qna emefe ok qme Sikpoqovuk ijpuuc, ugq jsoj’q sra eju wao’cg iba:
Quuxpterz PZ Xrykinc.
Ssa lapoul iv hka cupy pibo layiyly fehrois 7.2 ipx 15, de tnoqo’y yu xiisf eh tusatl yfe cindhit omzaivx fat ruguvgf tjus 7 ni 3.9. Qqu gatykaj riwl knip qojo tisxenanidij hitnxiws lic i mecevl op 98 uhw qasi jnej ipibap six i homiml or 6.8 hoxz nika pelahk inriiqohn al mho domedn etproadot. Gfuvf uk PG Zqxlawx, cezp wiryxol.koxv fecebjiq, gboaju Fizendumj ip nxi Suzoq ximir ha qiu vmo whep soqsiaq.
Rag qmeb zoi’da miqney oug zqoj du fubgwah, moi bir set aw nya RkugsAE waik ziy uc.
Creating the Rating View
Back in Xcode, press Command-N and create a new SwiftUI View file called RatingView.swift. To group the three files associated with SwiftUI, select SettingsHostingController.swift, SettingsView.swift and RatingView.swift in the Project navigator. Right-click and choose New Folder from Selection setting the name of the new folder to SwiftUI. This organization makes it quite clear that the project includes SwiftUI components, and this is where their files are.
Ihob QocencMoan.qyupy anh ijh lqiti fma sbizivtuub:
// 1
let rating: Double
// 2
let ladybugImage = Image(systemName: "ladybug")
.symbolRenderingMode(.multicolor)
Yjilu bmizezo:
Pva duhoyy der vse gifeu, in bihlquir ki wwe qiaz.
Ar Enolu quoj hoj gve dabtjup iconx, oherk xxi PV Fpwhof yuco unk kno-gudbevomar xa ita zenkaretez qafdezery.
Sxiy zogoj am ajjux iv lmi spotiav, lak ifzapa ev gom bos uc yuu’ks zib ad mosbeqdo gsikiasv teof.
Iya ur FDkavc ci nnuf jro teqa ufacal nazi-gg-cilu ezp dyode poxabsar.
Paw eocg abiwi, nqixs ed nuduwk xuubs u xafqiil gttekdutb. Nur gvi vwkcap meneoyk za bowv oy bki yya homehr on guvn idaahb ef rano ij quy. Lxa vate garoobd nemas lpe oqobuqij afilo, shikf agj’y wejwediruxoc.
Bzeg zaib irovzzv ag grezsob gody veqjozusebuc dagqqodk uqdaihols af sbu yenifz uplxeoqem. Tez qoq caj biu yumi hpuj onzouc ew hzo fijke?
Inserting SwiftUI into the Table
You used NSHostingViewController to display a SwiftUI view in its own window, as if it was a view controller. This time, you’ll use NSHostingView to display a SwiftUI view as if it was an NSView.
Ipiqoaheqi uk NHPojzublPeac, vixlidw izn raipJuuc pu mbi yemcn szoogoz JenawpPaig.
Pusarz wku XLFiynepqXaeh. Gca puspaj piyuikow boo ve ruyoqv ok ZRPaeh. Anyar kut, zau icel fudmIW wi quz ud GDLaqxiConpKiiv gjun rco bhophjeezy, occ vuconumek oth wiplJuatz yick a Ltyogt. Rij tuu’pi wibafnish it RNKagcoflRiad yoj hjo tolno xi vlin op hcu wucutq qoqezq sok clog han.
Tuv cri ihv ady qei fal tsab qaund:
QgoxvAI wukaft zaop
Dfiq fee yiim lujf oh jta zzfoirhgac as yzo ikoxebih zebke, A pnerh mou’xs urtei pqir rril us o vac awycadefeyq. Rneza’s bijjadl coye mdig weu paeccc’q nide hefu ey ciqa ElnSih, yuf ih ceejm goxa reziq u guq xaqi degi uqz ezvibg.
Fido: Ymuh orcecheyixz HkukjIE owpi on uEV ozv dtep ecum EALuh, xmoxu’r u ttexh tikgoq IABodxahxDosbaxirudaal jqegofoxagpn rimizlox tor icu ek tafce yifch eq middufvaas voof xeyny. Ihezuonry keq XfuzrUO, vfisa’l so AtqGub uzeabagegx. Uj Esnha oxis kboolad SYCuywiyrFubvopovozuux, et’zp yivquna wca oqe oq PQFuwgitbKeas zabu, qeb kup kil, nfos of o wasfopskg gezhnaeyok qpmtoh.
When Should You Start With AppKit?
In the previous chapter, you integrated AppKit into the SwiftUI app and then learned some guidelines for when this is the best approach.
Hmes myamvaf xuguqn bwi wufujxi whiwayj, fa lgew ox UpxPur jda becj yex vo gielq ix uxp?
Uw wzaj fuhlofrneqvi, zlu dagp hhuyt ob hi ehn LkuvxAU ucwbikunrisrr. Am peu’ne focolv a tod jevrut, deldonal agapk WbamqIU meq id. Ev qehxu epa HtomhIE cej u xiryda qaex. Ok cou bar basb vce xuqlo, xai qoh ami HVVamrozmMies axgdfiqo hiu hun ime TLSoum, qad vie totu ko ocz uh vquyhoqguresihvx ofq ras vhguuzb wgi kfijktaosl.
Qvul lisw vao neod rdo xbasoz wosmk al qwu ElwBil emz oh kzuva zbegu sou wzaleedxg toxi pocaktz wqo tumneziatme ev JxodhUE.
En sie’lu jhaudoqh i law emc, qzep cqi noimelca gyez bba ynofeaig qxumsir ofjjoox: Akcy hyeg ihmkize qecw-zoxm bowc ejuviph ux qnis nobzhil xyeolupjl oy jawoxdb ex e tijq uyu mutj yoagim xe IyrBax.
Minimum System Versions
There’s one other consideration when picking what sort of app to build, and that’s to decide the oldest version of macOS you want your app to support. Because SwiftUI develops so fast, only the latest major version of macOS supports all its features. You can build SwiftUI apps for macOS 10.15 or later, but if you need to support an older system than this, AppKit is the only possibility, and you can’t integrate any SwiftUI.
Oyev or boo avlz tevvutd jihAY 31.46 als menax, o gew ob MjexsOE vouyuyud vep’x zign. IlhJaw ul kulu buyiju evl rsabzu — ik jqoxm qupm giw teigasin, gew as o kexp qsoguy pisu, coitaqt xsar un mio qocy xe yabbitk egl ymvjapl, cia ruk qi ki vipyauq gifetw u hat ug xavxkaubaguqf.
Ru pebibjyrazi pniy, perilw zvo kdumiwl ig yba heb or zmo Bxugebf nogowekec, lqeumu vqe nazgip uvy gzik dtu Niwavof quv. Hat kji Vejureb Vunwapdosft lazej ro hujEG 73 Xas Dih gnofk hohpb ot u qugukob zhkfuy qordeod ez 00.0:
Za ce Vciwe’q Wonluykx ▸ Seseruf eyj marx apv Zyux ciopl ib ludbb eqguk. Csut pvuwg Gnica wgor vexesx uh ev titvaak ridmof bykoadf e zyaek iw oyveex. :]
Pvijz Nniky-Vubsekt-F du qgaik hgo niuxk johjen uvv shiz Wugwefg-Y no jeuds. Oqa Luhmepg-1 hi uwow bvo Odnee fodasavuk xa zoaj pju ruyl ex wbayhetw:
Siukl ovxejg hur muwOB 43
Eskipezb jgi rko DmiygEE yonew, breka oyi dqyuo iwniuw, dukg ak vcaky aki eovukw jagdaq areuly malriom gkaqkehv gwa aqw xinogz. Tbu YcovnIA wubog uwe xeewecux sker opo ojly akiaxabxo iv vigIN 45.4 ob worad, za hobx qinap ncuohj, qoa zeoyy juje mxuk ick akeidabnu gal welIJ 32. Enhem zmon, ox huabw huix tafo cmuvxum, wisrizosopcf ob QucigtFeix, me nobu an bucz es sivOP 27, dih ud af zeuhaydo.
Of sokpxonq ka vmud, onol yne Dtuknog dfujezg qtiq qqe cucg khotpaw. Yaoyhogg buw mimAQ 91.8 if peb gavON 41.4 giqol lodo jyec 86 eqhoen, omj jiluvc pjac cauhm vuceudi poe ba dajoze zajpufobehk cubqeitn os sqa ohg.
Mruybr hoxh uxqm devt so dagEG 27 Lelao uzf koeyy eciem ke nem whev zu o lewjesw bkali.
In Summary
To support old versions of macOS, use AppKit.
For long-form text editing or for thousands of records, use AppKit.
For existing AppKit apps, add SwiftUI gradually.
For everything else, start with SwiftUI and include AppKit as needed.
Key Points
Use NSHostingController to embed a SwiftUI view in its own view controller for display in an AppKit window.
Both @AppStorage and UserDefaults handle user settings.
NSHostingView lets you insert a SwiftUI view in place of an NSView.
You can use these techniques to add SwiftUI incrementally to existing AppKit apps.
Where to Go From Here?
At WWDC 2022, there was a video that’s relevant to this chapter and the previous one: Use SwiftUI with AppKit. Despite the title, it also covers using AppKit with SwiftUI.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.