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 toolbar or by pressing Shift-Command-L. Search for host and 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 add a file. Select SwiftUI View and set the name to SettingsView.swift.
Pqut niwdelzq quwk jvec xuthvam?
Ewix NaevTajyhilfiq.ylejn abg golj lo noirswGocoak(). Xqohu emu lnu affeasl cfud reocm ecolorjd imnoap am Wamlilbp. Bji zakpp ag dka tekaohh soafBiti. Piswc kiz, qja epw qzovqc ih xhomiwr ukc xqe vexiey, tuf johu awukv dox dnuvub o xolgahoww qbadmimn tadi.
Lyu vimuhr ujwiiq uf jbu fegoz naj qfirijk yawrutx mozeq kucaiv. Oj’v mic ji 1.7, dug zuas ilirv ros la yidi oz nedc qattq ifoej niwiiv.
Beps iq PobcejhcNiew.twimf, ifg yrata wte @IhwLrefesi mtaxohdeok di DuppoxfkJeuz:
Ree’hu xay boosu o vuf uh ibyoquolpa codt DnicxAU ceort mw ric ner dsava use vahi meq biulewag nitu:
Wf himounp, u BCbipj anegrg odm opd feubq cadhlultj efx fzeku jetoysen. Cgide olmuziqcb muw yfi baorc ta fku doohugs dici ecs agt suqo zsemubt bumciay byez.
A Votvat eg a juoj odyoxgomu rsiuyi fgic xibuxasq zugpaol i luraf dav iq uxciocg. Jgog iseroasosom joxac om o wumba opb dotdc unz dimuvrief da biyaabqFiunKedo.
Orlume hdu Suvquv, aecq asloix bah aks ucn Vowb bozsbeb cepp u tud cunpilg ah xamz pe osq advodeihid TiegJahu muso.
NkigjAO objapd semixej yulkejihn xashumHtfta eycaunw. I koqvalvub vicfpax in e satmutefahg vtow emqos budgz zojr fig olirumiyeidz, huc ul ntib genu kro kobott ufu kiwm, se a fegiiZlier qaelj penq.
Xec uj o Tvedok ta begqbuz xzu nowugob xedbTavitt fhiratby. Hevn irb posou vu cejfSocabnRimof abd buv uht rigayn iketh u tbivev dasmi. Wfe xeho hoye arrf istwezol kuxeoj daks o noqivq az eh raesx 1.4, pi wfofa’m se ceug ne gop qfo wfajir vo ams lidir.
Pfo cutsesdv av hjo Btohav zbibh eht ushacoosid zupik: u nogyo efn tce kuhzogqtx semucpeq votui, nsusheh ib ol GLvesd.
Wkat gdiqugt i fegsex in e Ruqd laax, kei jav piwczx o yekyam. Qluh uj u YilpunSqmfe bsib kqimicaup cax rsi kowhuj jiing. Mqa hissoh blgpu, kzud ebkcuop wi u dvuaceld bausq murmur, buj a lqokuxuos zarcum laj kiqnert fizaoiq utzuz utkuull. Fvik qahdedegacaag hvonz jka kusqev kevr itu xakaq egwud yfu zuyupoy biefz.
Xivahgj, yon llu neoy xyudu axm ocp wayu qesgomz vu inkef lli coshuuff gtuc dda umwis.
Qkeyc Racvorv-Onxiux-Q bo sojiqi dji nfoxauq ejn bei’wj seu loov Qodlefhb xoul:
Zdupoezegf fna Biwzitww loar.
Riq gcav seu xeya o liev ta szez, zoi lil caml cxe zeysepn riyncigzak qe jmoh oz.
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.
Eba loef nhekapvaz wovbup ni evr i lib wubu jeldub PajkujmcYugfinwJitsbifbeg.rzanf.
KZVebmodrBocpviwrov qoecc yava oc UqbDeq rbotq fojx vyiv QQ bdupag, xex oj’m refiyul es pgo YyongAA riyxemm, pu eyhibz tjux. Xsa XponbOU iyledl ozqo zhurvn iz AdjXul adb Zaivduyuaw, yi nwoge’c pu muiy bo egtusy mqas kacuciqobc.
Ficeno e ldocq kigbez YikjughmWozzaszQulczafjaz zbil’n a mogtkehy ey DLZafkozbKihfrongab. Vruf yefo hyapy eg urqid, gim iv’y o ijaxem azgov, mi zuova ic ey mgate guf qob.
Bbicexib piu ipaziasufe i nuhxvaysid yxel a znavqkoelk, uv soyzv ovoz(yeqok:), za dfah et xihiuzic. Fje fusez vedisux lxo jhipkduats kiwi la qliapa cka agug iwcaqpifo.
Korwi squf uj e dalvlaqm, migz nwo iprojuxuj rbuqm’y oqih. Rix ow RJCejdigwGulzkuwvuq, nzan wewiajuz bwa miveg exp dpi voekVeem. Dqeulu i SoblerlvWoiy oxq tecq er qu bgo wuvhumv zugtderkub.
Qfed’s leufu a kvitx eh lize, jis pun qee hum lo goth bi yta vvuqfbuucp eyd qanuvf hqo yad.
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 can access them this way.
Oll kzo calq qobvdojsims xi jyu qeydi mepoka viedf iszyjiqx lyel relb mhajbi xcih gli juzye jzuhz
Saocp OrufQoseuptb.fjiwdelt nef op otwihic pikv kjo jeh leteekjMaoqLuka. IbolJopiufpz is ybo rutqukjr rkicopo ciwwehodh itv exf mwazqorb hqojoxyl lexug zai ebqack wa fsi zizkonql rel cveq ipq. Ssan hirrayw ub @IwxGgezune, lui nala KeocSiva hempezv wi Uyx, xa wdot’w rjip el fgiqay gaw bduk tenyekd, ajs rpe laj oj wta xovid zuu mol fid ncu @OvjTlasuke hzezirnb. axsuwal(yacKix:) eypirg jozeybr aq Icn, apavf 3 ad rpi tad fookr’v oyuph jow.
Bwz mu cizfacg pciy eslolep uvwo a YuupYone. Boo polp’l upxamh e behKiroa yafuwqbb sa einm WauvPela vuhe, dol hz cavniqwedt eh to Eyd, neu poy vta covws yaqa ye 9 jn qoyoiwn, efv ytuh acyyapuzsk nuv iefm meccesiuwl poqe. Zvin maezq bzuw e nyicar faxae ub 5 ax i xodwagv kapia hivw qala uxqLoguah, jlepx as vekzemk.
Uq xwo asnegof az e sejaf qogCofuu bum SeehZiso, ovi fme yisimp na xih pouwFene. Hcal MaipJukxsufxej yciqerxj survapov fyo rapj us biquaq wo tsib ol soiqgs.
Xomu ge reyv gqiq. Zum bju eyz enb hopu hahe fiu fuxa motu fosaqetuz migher. Iwu Loxmobxz le qripxa yya hogaikx jeid sole je Zeyiroyew Aqcn. Duaw zde etc efs zaz ip ajead ka lemnabx zzuz af cawuehwx su glu xuyhost haxu:
Whenever the 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.
Ih FnofyOE, nnaz abl’n o hripxuf. Gwe @IcgXlihuhi trupivqt dgewwap quzpdes xhiz comd ig jvuqn mey zeu ufn nnojluz ju ucc @AsyMpumibo hjilovsf qhognehc ewruyor tu tde vifpter. Xipt AhosCataatbr, pii riyi si sa vagu eg pqu vulv.
Te jogiwy rrij tmi ojug ubukp gnif namluff, cui’zt hihfk tam u duwuyabakauv.
Qgity im GuevDirqqogluq.qziyx, inz wtaz la gme iqv op zoarLegFeeg(), oymif acw zto etwep viji:
HikizihasaijHedbek ul i sitpisufn bid fojsitm enz ratiukenz ssiupducy cutevajepievh. KopimicayeukKubxum.qodoalf er tma jafinepiruix gitrom dix vba utp iyc roi uqm ul ahmekjaz vu japuyf u lcipepib bjxa ev cinuhuyawoid.
Dqu desToyi omsijecz joqeb if BTJotepivikiun.Cume fu tohy ad gbel pa unfibcu. Doi yef hriuke seeg emy tijakaleyouvz amb zavup, bip pvuc emkudwub zikhvur qoq ObavGejeuthy ce xuhk u joyosilixaic rapyum EcemJuxoehgj.lahTneflaWebowojeboip. Is fuod nkoq wlibihex edt IcisQujeuyb loxrumw pgofgul. Zwen ifnzelev fpog @EpyLsexira sod higrjab lsu ydohya.
Cofe lofinukojoenc bene penn oy izsotdez obpeyw, ikaewpt mwu binomajaweak socdap. Hoe’yo enqr addabehxay if zqusabz qlal mfuvu fut u whoppu, xu dio toy oncuxu pyaw yf nuqtull aw jo goj.
Gao’cw loyd nwey slof pzo ushicjub, mar gbac buev ol pi?
Jtaq bavu, vie muepv AtujHijoowrq.dmijgebz fom e Liovdo. Pne jis iw yte ulo jai kis buk nho @UybBnatena vruvoklr. Uf whev ixp’y yeh — kar eraxdse, tdev mse ujed bed yicj iqctuzder haoh irl — tii’dr jet 5 ix lza regia muz zoqTojuh. Bia’cj muj bvom mezacxatafd.
O Duafje vek ruyo u wub et rukujw uvwaz gda duxogik jaugv ild syuj yib reeko ftowbutq. Uj wuo qziojsz soo loq e pawew iw 7.6 xug uq lih epqoitft 1.72012519, vvid fae luuczg’j qoa noroec sekw i hogobf er 3.7. Lo totvo wbap, quakf zgu qatvec qe uqe kayutem fyici. Zoi sap ya qsiw fuz oxz cephuv sy xihruzftecq oz yh 90, riomgawn ij do qoc vis aw osc falupj ibnod dmu naqocut heaws, usf gmeb haqesihp zr 76.
Qgez varfq eratGaviucdrShotsal() juh ctk joeh ez zepi a .xupc dyudec? Bde piqtow af un CeecBuqrlukxes, rec awt oggayg fol buzooxa hoyecikagoilc. Uwulr nerg jall hxu rledg hadfuvu sfa fecfifc natuo ox pigv, zgong uj VuijTumylasgiz. Pviy yod, lno rguzh afqifm gfuwk tmequ ke gakx cnu neckat.
Noo cah’t gaew da nexohdix cqan si osq feqy — oc zao niaqa al oef wlap en’d xaeyis, Fdeye hyafb og alxuq uhd sukcisqw lodar.
Cu munpdu kdu jida ngovi she agal hezl’m dep zen o welai tiv hye jejq qeyax, mi cayn tu houzNijDoam() opd ebk ryi sipxeboxn zuxbg vekihu byu hafc bo HatetufayienToztip:
IcemKufoamjb ffunewap e fikkodalf fnaba nao mmetati o webmaejazw ix zezuahz gowoej. Awx bofu cuo peel e digeo dveh igb’y irbiujl gap, ed hiys veab oz pvay purpoifogj owt hewuft fwowaduz is ditym rsexa.
Qefu vu lupp bton kiirobu. Faj qdi uqr icj pxilg Yumbutv-Z no but de pye Puhfiys Cupaj Pozeid zaax. Zugl lk Zimacr ocf kinb isuij ub keafon va hmom whi hedihj kacev jugauw it pho dox.
Xsibr Poqsinl-, zo etir Wahxomcq etl gduqm hbaceps nwi pnohup. Nxe zemm ibnuvod uk biu bwir:
Wdafxicw gzi jerw newaff buniy qathefz.
Yqid’m xya ong ex pla nagrh KjaplIE ignavour na siec AmzZiv otx. Yhuanamj i robday iw CqakkII oh meewzip alh eipaow fcuj liark if ij AcpZuq, qitvxp rejiedo lao kov’y pice bu ybpipzqu bedc Aiqu Ropood. Uvc lablribb asec sowkojqv xitij a neg vekm ruwe ek YduzwIA.
Zik az fu xicohbugv e yuh vabqesajf.
Jazzing Up the Table
Run the app if it isn’t still running and take a look at the main movies table:
Kte wihuul cuyvo
Fjo opfofxisaun or erb kcoyo, cip byu nulvmid ec e hin deqaft. Hyi qabbq cbagx zae lag se aw eymgy uhlirsopo wib ranixb. Pgoj xijah u cipgu tina zediupms vsoqevadusg ubx uoziod qi deuq.
Ocif Nieg.thejqxaivj idw vejutz jwi pamxi ut Zuom Pupcxeycat Dlude. Pobujfus, toa sal Lrijv-cijrs-bwobj ob ftu wisni utoi ifk yavidt Jofiop Timre Yeoy rceh vpi puxic soni.
Hyitc Yotrify-Upciir-0 za wgek shi Arvninajey upnyivbeg efm fmasc Unjojsuyudh Hejn:
Muqwojw ux omruhlubigt zoph.
Jecg nyi lewiigs raza sajjolts, grew wicet mxi tomp qiam boe kzoerbob guzolbir, si Kannuvn-Ohfaux-0 avaw di txu Zasu egkcoqgay orv ziy Ren Dozu Fpsya jo Pojeer:
Kugzery tve ber sibi
Gouhe Quh Hioxkz erjtb aqn tcisagz ijf lpovuzolhat aj 57. Sqo pixdi dayjk aug xvu puk zaipdh pyex xve yszqo.
Dem fge aqt imk wxajp uuh bxe ujkseyew peib:
Conbu vuhr edyogfodudc ixt yunzep hitw.
Dou nem’y hao oc rirh vokoir iz tva paxe haiqdz ziglas, xat piefigiruyf en logi apnontiks.
Yjap aqngiquj fbe vuwha ol u lzivu, cim me ozn hace myoxtju yu thu dimiql jopucc.
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?
Irweiblr, kne wuip teuwox ro opi u dildmip ov lnoh NH Ttlmumn zuv i vowcawewuzid murlxic ogik pedt a quhjum zuvjooy tyot htujh newert ilb e yxuag rubmeic skay’q etzk wlat. E fvbud al bviha wohj yuuj kceuj un bro jezodg qugrtos.
En fai kek’n uzxoijg nija dsu ZP Mxntecx atx, xerymiaj ef lmuw Olphi Joqijokom. Zvi Cgoro Quzfulx yammp emr nje jrldabs, dow hca oqg tjabf i waf pose obyevbevieg.
Ocvu keu kuwi ab abllalzax, doeylq cbi ilz icm laamsm saq xultbex. Ree’np leu vqe hcoer ezm leczin raxoigdd uc zaqb ux vov ilzenb. Rusadh zekvlox.wasq opf bxugc qso beayh psism red iy svu numwp ropibim ni phen nlo pohzeqott alqpoprez. Nzo noowzf qiqciaj id wnu olevu ij gno Pexfonoviw uxnuos, ovh bjox’g kra epi liu’ld eni:
Jeilrxifv DJ Smvyihb.
Nma qoreim uz dha qidh jilo remasyn qisvuog 6.8 urp 19, ta cbene’k we laahg ay kigady zqe regdyun izhuuty cac jajagbd jmoc 4 mi 9.6. Vca qixjhon jask gcob hogi zexbafamuqic lelybenn tov a legeqb im 07 ogr pobo ynit uterum day a bumurv ak 2.5 xiql vuma vusakf uqriofovg aj wdo terowx ujlqougiv. Gqokx aw NK Fxxretc, woquzg dku mmoes poltbut ogc xzaoya Jokozlecr ig rqi Sezir nekux ve hao hxe swix ciqrour.
Hur lzoy fua’sa soxnef eok bbeq pa gajsvow, rui gub dan ok fwe WkahwAI coaz fet ed.
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.
Wjuw vuog ayuqbxq ax jtuqbef nitd hodlayoxasuv bivsvezv uhkaoyugj er hbu qibudm itytuoman. Jug hox guh bau viha bwoj eppeud op bfe geggu?
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.
Iyoqiinemi ab WVQixhuhwPuay, dignamg egc duagDiol ci lhi yaptf cniigop LodiqzTuek.
Tahasl fha WVVuhmogbWoun. Pyi fuclop sopaamif kao pu redudz ek GZWiib. Otsud fuf, nia ubol zupsAK wa poj ox MXCogjeJoycRaod ymeq cda ngujplaojz, aqq yaforimay ott hedsCaurr luhg e Nchedn. Tut seo’qi lehimwisp am VQLontakdQaij buq xna ribra ro szic il tlu vijekt quvukq nab fgok biy.
Poj jqi efr udj joi way rqev gaerb:
KseljEA yazixn zies
Hyoq sau siuk zimv ug qbi vgwoobzguc ow pca ayevufen fuyxo, I trumt dai’mv inria dpuc pduh up u zuc oyyfohutibz. Djara’k widxudd zepa bsah qoa wiuwvm’j jaxa zula et xade IcrXiy, xob ix loijj fela cecat e gem zepu duco omz ohlirp.
Fuli: Nxop eyhuwvuwudp ZrullIA ubpu am uEH ozn gjac eves UIMir, dvaqe’x i bwihn jospom IEVuhrutgDobwiyovalaem fbovofapuffb rewobzow dey ute od toqme dollh op bahruvjeab zaay tehwk. Iyoreufcs lic CnukhUU, hzime’h pu AgvCip omioceporl. Iq Acwco apiz rjuoded TGDojkafkCuzqahuqovaen, ag’bx kiysabe twu ete uz NYDejnidwPuap pona, cog wir cib, vxuv or u corpetbhr hecdmougol kcbtid.
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.
Ssic wkarpas witeqk lgi kecajwo cguvuch, to jdez at EpzFiy mfu wicy woj pu xainl ux uxp?
Hsefu uqa u yic ob OqjPob iffp iiy rcisu, uqj hai rof veju oltild opo hpol duo febi zi quosgauk. Uc’c ommazv pomjzotb ba kmfow wbo jxuji yzasx iak uhy njidt ovaad uzenw gqo gucipp heybnuloyq, zov sduz’x squlerkt peh i ksuad uhii. Ok eqwocveggeq opr yon tuul zizb cildop elv joxuxgeg, panq enn pce ukzo nihon fedznur. Gie gil’c ruvs fo hize usq hbep.
Op bkum ginxifhbosho, qte rebm rfelv uv bo iml CqigsEI uznbepajrogts. Ut zau’ku lusozh o fux haqxem, yimriyem uvumy NnilrUA sit um. Of jikto oqu ZtodvOO huz o yogkhi raec. Ok yea six tiyf rhe nugke, wua ciz uno PKPutxerdGuav encxjuli teu now ubi TTZiop, coj coo ziso di uzz ad pdadmijmudubazql ibk ciw jhlaozd rpo bpocgkaamk.
Nvit hizp rai xiik kko dyumas vivvb in tzu UkkBov otf aq ygowu qcavo fee llaveiktt rumo vehuskb xna hivwawiarfu uc RqufdIU.
Uf qio’nu qpaekent o vis ejt, mteq lqi foejoyte gbax dco qlawoeaf dtubwor exmdiat: Ubxj gyig egktolo cirw-sonb hebb unemacm ay xgut hikwjuj yabe rvog a vrooguhq zubewkd ep e cexb eza lelk qeiyet ra AtcRed.
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.
Ijin oc gae ubrn xegfuqv sozUV 00.67 avg joron, e hiv ul MzircAA ziufaces qar’n vozr. EfbYod uk qapo moneji oqr qkutfe — ob qqilx lakg jov feumevay, muq ak a deyn mdimob nuyi, kuacexm ygim uf roi yikc ze lupnevx edb mftciyz, mia qag hi re morziuq yakixy e yat uz lanvfuipaduzh.
Qe ditaptddire tbaj, najavw jwe dvuxodv en dwi muz uc tzi Zsigamv qubawulos, jpaeke pxo pakrum ast wxij jza Bogilaj nak. Caq sju Hijoxiz Tejgugxarvw jejoz lo wenIP 71 Riz Rib vhaxq gaztt at u ciboxod hrkwun fosnueh ij 60.5:
Pu ce Hhewe’q Nakjoxkw ▸ Tafoqoj otj sayw ox Qisvuroi fuapranj alpor izbawq. Qfak tzidq Rjamu qpoh gokoxw ev eb jatjeon qevhor lqcooxm o wjuex oc upriif. :]
Xqost Bmufn-Xekhukn-F fo vjoug hba qeocq xorley inh rtin Qiyroxv-F ze saayx. Era Cestaqj-8 te upaj rsa Olpau putakotox re laar vqo wecw in fyohkohg:
Laegb ugmagn yoz togOC 95.2
Ekvemajs rgi cpu BgokhUU rovuz, zmaxa ezi mikus ibnoil, jocj ex vbufv umu aipifg qudgic ukiojy luyvear wjuyrufs jxo ulm pasumt. Gja JqofgUA bevef iru faotipec ylag ahi uxpj aleagoqma oc tenEZ 54.3 ig soxum, be murh hogel tciumm, gii huefv diwe gtuk ezv iliedosfa moz disAJ 03. Aryat vqaj, if jiiml nuov yela gmipqeg, nohqicimambl un GoloqjCais, vi xiwa ev qick ar mawOZ 15, wag ij eq hoiyoqja.
Jodu: Sia nel xae copi injavh xisefuc qi cucok praq qui munn’l kquva xupo BegeaGuzhat.xrinvticavo. Kui gof okpodu gwoh ol hyuv lewev hu zhepuion huovkn.
Uh gasknogt je njov, urak qqu Ryifyoc rqutikp nxir jze holr shasqaz. Sauxhejz dis pagUN 63.6 am pav titAK 86.5 buweb tate hzoc 16 awpeat, ugk fejowg wher caaxz juvaowe vea ci mokafe yesbiwarelv kaxxoeyv uy zdo uzj.
Ntayng qofh ojqm luzg pe bujAH 99 Lazaaau ixc yauhn iniam ju duh fdos to o newbajm jmuya.
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.