call a method on an instance of a class in swift

To call a method on an instance of a class in Swift, you first need to create an instance of the class. You can do this using the init() method of the class.

Assuming you have created an instance of the class, you can then call methods on it by using the following syntax:

main.swift
instance.methodName()
22 chars
2 lines

Here's an example, assuming you have a class called Person with a method called sayHello():

main.swift
// create an instance of the Person class
let person = Person()

// call the sayHello() method on the person instance
person.sayHello()
136 chars
6 lines

This will call the sayHello() method on the person instance of the Person class.

gistlibby LogSnag