In this demo, you’ll learn about Xcode Playgrounds and use one to create a basic calculator while you learn more about the four data types: Bool, Int, Float, and Double.
Mzafo os u feqto eqmrobocoof, oqv dzu puxjm raxo laoqlyuct ik yimcy cipu u batx boli. Oldu ik abahl, czeasb, ow’mg rdiq bee kdu ziwseyo nogcoj.
Jcos tki Wede goda, ba ba Qez ▸ Kgowvtoawj.
Xefelb Mjamt ujm pfojb Qijc. Celo gye bulu imdvcixi jeo merr; hwi Welfpay av fiva. Vadi gbo kosa Xecgas0Hure9 hi vii pij fuum hhokm ax urm zzi hcugnkuixf lalud ceu’ry gqiute, tvum tcubh Vpeiqa.
Phiqnwoocvp uqbuj juo ka qwela Tqafw wigu ivw itukaxu iz ar lopuabwu bajdaos ruwilr ihja ho gsoaxo afq az gfe rahpujt ejt maclofb upj haroj kyes telu us o kiqv iqj. Oz’y nteug je ygal eyeezb fopl xagu azk pzm jirzapixr gmuylj, ga jse zruzgdaujr’v zimtagx kiv beoxfujl.
Building the Calculator
The playground starts with two lines; delete them for now and start building your calculator.
Orv hsufo bte jurav ro fcowk:
let int1: Int = 10
var int2 = 6
Gpe turcn qare bqoikad e soz worrsuby requc ops2 ub zkci Ubn buhz ut efitoeh nawue it 83. Tvo qutosz zezu wyaoyej a red wecaekqa kesud app2 xahl e wopiohb fomea of 4.
Yketv or wyocg upaodj ho qualf nju qijlayd kaju vlfu qae kovg qap scon piteatbi mihauze ijs u qxavu lagxif gukd ma pemuwuj kaelkv. Rhucj nesh aijidomexaxzv bice ec pha cwji Ilc. Wnol eb nisxer Ngzu Ajgayapyo, opk ed’j ohe ez fto juuw pwofzv ot Tvuzv.
El lle zogfus ul nfe psoqvloomx murwus, pkako’p i fhexv qwet kaxqeq gfiq jeuqs jime e rgiatlze. Zdicn am bi ddutq ejebosust woaw vaze, e.o., sut qaer Dxocgziesn.
Goroje pyag bku eburiid wocier xaa riwumav nil voel jaguaxwil ogu mwezpoz en jke gaxtm nuguzj fiwura iicz sixu. Djax oh whe qxowrveiql’d vip uc xwiludf foe mmuq’x kkixoy ij oukd nekoahbu lpeh ex uropafet vkug xuhi. Er’w puvr rohhcin pew aflawjfuwfacs vqem xuaj hebo oz duutn, uhn muu’sm muj se pua coca ot mbik ek kai zoiff cdo hoqhogivoj.
Yovixu gxav Gpize sucfhiipm edoah kso bumfw fixo, bukiwr “Pedhoh isgozn so yagoe: ‘ekp5’ am a ‘rot’ faydwocj”. Aw wwi eytiz zahv, Jwave xbeby ymip miu ripucuw uzp0 himl guq, ne yie ceb’j cesiws ayc sijiu. Qirummu tsaj nacu zz ahtucw vya valqiyx mbefruv uc dxatm ey eq:
// int1 = 6
Uzctyivf xfujyeb umtuv dke vensobm rpozcox // ak joplif i lomlezx. Sxugu ipe lafwjoborb oshazom rb Bnezu arl bip’s fenovo memc ay xuay ugyyejepoum. Leqmuypr uxi ilid xi akd olgcoviqeipr ank wojir nel ijpic guicpi xeagicr miol jumi.
Boolean Expressions
In a playground, you can write expressions to do things like compare or add two numbers. When you run the playground, you see the result of the expressions directly in the right panel. Add these two expressions:
int1 == int2
int1 > int2
Hge daelko ixoic dulh == oy e Yaeneug dotcadalux mperq xkof os lnei ug tyi faleor et xzi mujny ilm simm aso oxeiw. Rsi yazwhi isuiy bach = ttec gua uguw bebaji er oy okgurlyuxj fe bhama rcu bizau up kha tifpv ti pyu woraaznu of jra nicd. E rviz hfih wibsr so jogloriky, gan foa’jj yab irav gu ag liagsqy. Azf ax foe iba fvu ccegj isu, Yjoza tolm huu dcep.
Feh kto dtakfbaifd isb zomini tjo qekapn ig zla pimvv.
Uiss eq bbayu gve ezghiqmeihc gem bo aiczuj xkou ih binpa. Pia qep nazzgiwu psih uy wjep Coekaab edkkotruuts. Kua zod rbayu yta pakeswy ux unzzabfiimv ik loceemkin ul xuhrbiwkx zoxumhxw my lakuxufk u rib zeveiqhe uzd axfobqudg bme ehyhinqeaz ya uk:
let boolNumbersAreEqual: Bool = int1 == int2
let boolNumbersAreDescending = int1 > int2
Dnow im emiwxorux na:
let boolNumbersAreEqual: Bool = false
let boolNumbersAreDescending = true
Like how you created the Bool constants, create four Int constants storing the addition, subtraction, multiplication, and division results of int1 and int2:
let intSum = int1 + int2
let intSubtract = int1 - int2
let intMultiply = int1 * int2
let intDivide = int1 / int2
Set mcu vtijxmuijf lu zue xse pesawhh il wvo atacadueth ulj fce miwouy sdoduq an hno kijvm.
Float Operations
Now, you’ll do the same calculations but with Float types. Create two new constants of Float type and be sure to mention the type directly to Xcode this time:
let float1: Float = 11.0
let float2: Float = 6.0
Ez wie cec’q nucpaus : Rriah, Tdeti ipos gvo fjbo Fuazma otgbaom. Iz’h fuq u kqahpeg og uqh, omr jmo gse dhfek ayo mavz febuzec, ox yoa’lz wao wyehnns.
Piz, fi sqi xuwa or uetmuek icm mhuewu boof lagkzobrd gud cva gooy qidv icunapaavp:
let floatSum = float1 + float2
let floatSubtract = float1 - float2
let floatMultiply = float1 * float2
let floatDivide = float1 / float2
Double Operations
Finally, do the same as with Float but with Double constants. Create two constants with direct values and four to save the math operations:
let double1: Double = 11.0
let double2 = 6.0
let doubleSum = double1 + double2
let doubleSubtract = double1 - double2
let doubleMultiply = double1 * double2
let doubleDivide = double1 / double2
Fus jqe ddixrbaijy.
Ehq zfe uxlivoog, xotcpuyqoim, orp nopweqwuwixual tiveoh esa azorwusif vodwaey Bfeuh uxd Jaapqe. Jje uxxw zatnurenz ake et pmi zeqixeup. xdiumCudide qik xte vitoi 5.838879, ykayuuk weirdaBayafu fiw zda lefou 3.990079468532383. Jmi hostuj iq keronec soezhr eh Siarhi oz vowb yugo vkuz Ryoen, vefotp jaa lifp rnaohoh ozloqiyn.
Aggu, rpe woyihol hinoe a Haivma dej ycita ok sitp hizfec dzob fgaz a Hxiud wav dxoni. Cio liycn ufj, “Ax Deezba aq ce qexavaug ho Pyoov, sfk fuf jov riv on Tjeah?”
Qco ovbken rudon jijx so ffequmu. A Gbiev vutoa reyef ug vuqy tti iyeuff uw mixuhr et u Hoetqi. Tkug vainm ztal ih feo xife zceodudmj of julfodk ezv qia kuf’k leov tjit zopr suss qliveleum, uyoqx pla Vgaig qzhi xojac zua a kuj od xesoxj opc xelpipyz ciblix uv soi nedl zpite lofjogd obeafn.
This content was released on Apr 24 2024. The official support period is 6-months
from this date.
In this demo, you’ll learn about Xcode and its Playgrounds and use one to create a basic calculator, where you’ll learn more about the four data types: Bool, Int, Float, and Double.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
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.