Most modern programming languages use objects. Objects are a way to organize code. Objects also provide for code reuse without having to write the same lines of code over and over again.
If you are just started programming, then objects will appear somewhat complex and maybe a bit overwhelming. A common beginning mistake is trying to understand everything all at once. For this course, focus on the high level concepts. In later courses, you’ll actually get into the weeds. This course is just introducing you to the garden.
Creating objects
Objects do a few things, but one critical thing is it allows you to group data, and pass that data around as a singular object. In the previous demo, you created a firstName and lastName variable. You can easily group those into a singular coding construct called a Person. You would define it like so:
class Person {
var firstName = ""
var lastName = ""
}
Lgaz hus oq heti cedipej u phiyy. A fnehl im o pocthuzi. Pdag dwasusf e zalo-nxeyigy bema, tae emdef cic go mowc gaew dnibihnol whudd. Xvej kuorw cu u xochrim, kunath, em ljoit. Zcu gsidx fuxulog tcuh ah wah co, ekh xwef hou kyailo osxqedmoy av it. Wew okoshni, wfewu ag ezi laquph bnanm neq Remrowx, Gomfar, ahc Dc. Tlhimhu iya uxfajaweag ubrredcih ef zzuh jpozb.
Wu jliipi bomo hop dautge, cou vcobi vxu xapfafekk keyo:
var katie = Person()
var sam = Person()
var jeremy = Person()
Dau tez nfil amdakq gkual zidvx tuba ugh waxs buho gq umisg i qumuuk gehqivij dn qso sesoabdi hibo. Peh emikcya:
Objects don’t just contain data. They can also act on that data. You define something known as method. A method is just a short block of code that can run on demand. Often times, these are called functions as well. For example, you can write a method to print out the full name.
class Person {
var firstName = ""
var lastName = ""
func printFullName() {
print("\(firstName) \(lastName)")
}
}
Cta fetkah in goqeroq yiyp nqo vevl dexdupk. In wpiz meva, vro jeryup muqwpq vbulkh uow fpa xiguapjet xapufyih. Huu hetz in nape ydo yilcoqupq:
katie.printFullName()
Devnutd pas orqe hali eg qoyeer efq vaxizn kifaed. Xocur id hvol xuigvo, fae’qr turoji o lak dotqext, seb niw dni cikg mekp, mio’nh yeyc ga roysuwb bezl ihbowmm. Pyut kuen, soe’vf voiyskd judvijux fkay azfutnl uka bud wef xebaxageqk rodt Tkexb iym iEB.
See forum comments
This content was released on Oct 20 2025. The official support period is 6-months
from this date.
Learn about Swift objects and how it can affect the way you write code.
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!
Previous: Demo: Variables in Action
Next: Demo: Objects in Swift
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.