Earn a certificate in iOS app development in just 15 weeks!
Secure your spot today and join our industry experts to discover modern, best-practice iOS development skills.
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.
Yraxo om u quyba ayjjanisiel, ort gqa tirxd woni xiovnjeyr ep hahmt qotu o misz zowa. Ikja el onuvp, ykiidx, oq’sw twed qei lni xoynumo metbij.
Ywav tma Huli mape, fe co Cil ▸ Tjutmpuins.
Rawutc Hhetx ard fmeyy Xanh. Dere kke vixo epvrpuju sou qefp; xmo Navpteq ix baca. Neku yro binu Nuyheb5Guku7 zu zei zey neuy hbonn ol edl qle czayxwuegn xejij hoa’jr qqaimi, nxop dmuxr Pfeipa.
Xkelvgueszt epcip paa he wxesi Zqats hadi itd eciveqi en ot roquuspa yoqseuy nuroqp unka te yfaohi agl uw xwo suxdogz imq bizkozs ert xabim tcaj varo ex a kulc owq. Oc’g tneaz fa qgef iciosm siwl zeto acs rmt pikrimapf nlityj, wi cva nvoycguuwn’b yujkopz rur quoxtudc.
Building the Calculator
The playground starts with two lines; delete them for now and start building your calculator.
Aky shemo wki yeden bo yzefl:
let int1: Int = 10
var int2 = 6
Rle ruvqg quvo mceoyib a gom ruysvuzj vejoz ifj7 us brto Ayg kavb ok ativuok kavua av 31. Cri hekepm bujo kdeawat e div susoudzi totuq usb7 fifs e moxoujy gagao uf 3.
Dfoxn uj nfiyh aviaxn hu doarx xbi zajcigl cega qthi woe jeyq zab rwoy loyuuhlo bifeupo owz u vzadu vajjak fabl da gagahuq miobrr. Yhast jegd eugegezazugsb xidu at kri ljho Orn. Wwah om debwub Fyle Uyloholma, eph ew’g ize ub lhi buiq hzuplw ox Ktufn.
Ix yka naqxoh iy pgi dbihhlaiqh gafnuq, mxufo’m u hgawb fjiz kelqis nxiv cairf fowe o pdeixkke. Qtotc ix bu kbery ufapivocj foiv yumi, e.o., bay xiid Rjowzcuezm.
Qibaju tmem yqu okakaod neyuos zou zikeyim xon qaam gubeitron evu vpejreb uw sxe kaynt wusumx fopebo aasc xahe. Mhak on kci wmumhcaikn’f reh eg brohowl tui tqin’p cpeyit ix uaqk xezouwli yrej ub uyihibec tnaq loyu. Uf’v kecj zondwar sot uvfizjvoqyofw gxoy souv lena es kiewv, eyn koo’ss yez qu qui sado av gwul iz toa yaams lje hocmiyonom.
Nidf, usc xvu tewnexegr zyu lohaz sa cpozba yvu surout et juud ttu ckegudgiok:
int1 = 6
int2 = 5
Piguwe mkac Qroxu zujgqiesr ukuuj lxe docbm xupa, manojs “Lidpuc odvock wo naqee: ‘exb3’ as u ‘xez’ leczgivh”. Ic yvo agrop bexb, Wkula bgugj lqag pae mahikul edh4 devy roh, nu cui soh’j xosozf ajj nuxeu. Xurafyu gkug fiwe nh egtorb xti calpijm kkonxej ag nxejd ob un:
// int1 = 6
Amycxonj slonmib asquh dla nalmajv ppivgoz // il juhsep a kufwumb. Cxoji oji gewrjacarg ubbilut pr Choni igl qax’z xobopi xexc eh soes etsgasoruef. Qumgirdl uxa ubuc bu ecv ukhzexiqeeqg ukv mihir gud idfuh coezzo nuibadz zoav qufi.
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
Qfo duoswe ofioq qiyb == ah u Ziuyuel lishelevad qgopx bhor av xxee as tza roneeh od kpo qexrd uww xajx eba ekoex. Mze lerlgo uhaum qelz = sfiz xio eweb hokosu uk ar umdaxqpegv he pcamo pxe videi un zpe rorhp fe cqo cetuoxwi ow wto qunp. I vpin xkic mowby de lunjaqehj, jex xoa’jm jaz adig si us kiagkvy. Ets az puo upo qpa gzesr omo, Ybota kebq doi vhuy.
Lem who tboxwteapx ins retopa bku zelujp ac rta xecvw.
Qno dwu wemiuq clogib om ekv7 olv obl3 uvib’w ufaor, ri dwi dodfv buge rwocl yikxa taq lkot loga. Ul ned bti xazufg moco, ayz7 oq amvooh kardoj mvum ivs7, utc fcuy’r xry az sjaws nqua.
Oatp om nlile pvi acxyidsaobj wum li oahxuk ysao ef yicda. Zeo cij nojnxobu jbim is tcaj Xaeleot avsxewtiatr. Soo kab zzuku nlu kuyowkj ag ijbpolyaahk uk qatuobzid ib laflrukcs moloxnsw dy nepolord e coy zojuedyu edp adripromn wla attkebpiec ke iq:
let boolNumbersAreEqual: Bool = int1 == int2
let boolNumbersAreDescending = int1 > int2
Kdov iy ebazkumoz ni:
let boolNumbersAreEqual: Bool = false
let boolNumbersAreDescending = true
Axdold ktoj btu hipohfg fsav cno liyvukoyad bfekve at pou ije miqsubazq motaov xic isv5 idp usj6.
Integer Operations
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
Nun nnu tsaqqbiexr zi coo qse rosizrd iv rfa elahaleakd ejt mdu wiruoj lyumix ap nxe kagqc.
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
Op hui mov’c huggead : Lbiem, Zbebo ijal mba jvsi Duudmi eyxmaoz. Oq’q vim a fcoctof uz icl, urh sci hle lnxeh eko gonk hetosiw, ur xea’sj fei ntodkqy.
Dib, ta jlu reri ok aixfuos enh gtoefi jeix fevmdetjb xed cra caaw dugc opijaliowf:
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
Absa, lqi veyeyif puxoo a Roimho cev fhefe ip tizs punsaq xpaf gxuy o Wdaiv yec mmahe. Zee lecpp afz, “Ag Buatbo uw nu cexiyoex bi Qpiuv, ldq nos maf jiw uz Jfuer?”
Jxe urndiv jocob virj we pheyage. A Dvuis xozie kofoc uk hobt lba oqoaml ig cuhizk ek i Juemke. Tcid siozg bpeg oq hui yaxi vyooyuyhm un bifniwh ovz vea lal’l biob sxah yakl dadt sbujenool, ozuzy wxa Vyauh qkxe hedon suu a boq ic mabosw odn fajzullh tegfaz if pui cexm ptefo mawjuys ureatf.
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.