In Swift language Functions associated with particular types are referred to as Methods.
In Objective C Classes are used to define methods, whereas Swift language provides the
user flexibility to have methods for Classes, Structures and Enumerations.
Instance Methods
In Swift language, Classes, Structures and Enumeration instances are accessed through
the instance methods.
Instance methods provide functionality
To access and modify instance properties
functionality related to the instance's need
Instance method can be written inside the {} curly braces. It has implicit access to
methods and properties of the type instance. When a specific instance of the type is called
it will get access to that particular instance.
Syntax
func funcname(Parameters) - > returntype
{
Statement1
Statement2
---
Statement N
return parameters
}
Example
class calculations {
let a: Int
let b: Int
let res: Int
init(a: Int, b: Int) {
self.a = a