Declare a Class in Swift


// Declare our new class 
class Person {

// We can define class property here
var age  = 25

// Implement Class initializer. Initializers are called when a new object of this class is created
init() { 
   print(“A new instance of this class Person is created.”) 


// We can now create an instance of class Person - an object - by putting parentheses after the class name
let personObj =  Person()

// Once an instance of Person class is created we can access its properties using the dot “.” syntax.
print(“This person age is \(personObj.age)”)

Learn iOS Development with these Video Courses

How to Make a Freaking iPhone App - iOS 10 and Swift 3
icon icon

iOS 10 & Swift 3: From Beginner to Paid Professional

The Complete iOS 10 Developer Course - Build 21 Apps

Swift 3 - Learn to Code with Apple's New Language
icon icon

Learn How to Build Mobile Apps for iOS with Swift, PHP and MySQL
icon icon

Follow me on one of your favourite social networks to learn about new video tutorials and code examples:

Twitter: @SwiftVideoBlog
Google Plus:
Facebook: Swift Developer Blog on Facebook