Declare a class

 Problem

I want to create a new class and create a new instance of it.



 Recipe


// Declare our new class

class myClass {
    
    init() {
        // Called when a new object is created
        print("A new instance was created!")
    }
    
}

// Create a new object of myClass
let c = myClass()
				

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)

 

 Playground