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));


Find answers here

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