Extend an existing class


I want to extend an existing class and add my own methods/functions to it.


// Extend the Int class
extension Int {

	// Add a method called 'multiply'
	func multiply(x:Int)->Int {
		return self*x

// Now, all our Int's have the extra method
let y = 2.multiply(5)


Heard the news?

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