Declare a class with functions


Declare a new class with its own functions/methods, create a new instance and call its methods from the outside.


// Declare our new class

class mathClass {

    func add(a:Int, with:Int)->Int {
        return a+with;
    func multiply(a:Int, with:Int)->Int {
        return a*with;

// Create a new instance of the mathClass
let math = mathClass();

print(math.add(1, with:1));
print(math.multiply(2, with: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! ;-)