iOS Development Swift 2 - Classes & Objects

Let us understand what Classes and Objects are in detail.


Classes are the general-purpose flexible constructs that are the building blocks of your program’s code. You can define properties and methods for your classes by using the same syntax as we did for variables and functions.

The syntax of defining a class is as follows.

class className { 
   var anyVariable = anyValue 
   // Function Definition etc. 


Object is the term that is generally used to refer to instance of a class, so we can call it instance instead of objects.

Example − Making a class and its object.

class Person { 
   var firstName = “Tutorials” 
   var lastName = “Point” 
   func printName() { 
      print(firstName + “ ” + lastName) 

Initializing an object − To initialize an object, we should use the following command.

let anyone = Person()  // We can initialize an object by default constructor. 
Kickstart Your Career

Get certified by completing the course

Get Started