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)



Find answers here

Hi there! Ask Us a Question We are ready to help