Page 133

Swift

39 65

Type Methods When a particular instance of a method is called, it is called as an Instance method; and when the method calls a particular type of a method, it is called as 'Type Methods'. Type methods for 'classes' are defined by the 'func' keyword and structures and enumerations type methods are defined with the 'static' keyword before the 'func' keyword. Type methods are called and accessed by '.' syntax where instead of calling a particular instance the whole method is invoked. class Math { class func abs(number: Int) -> Int { if number < 0 { return (-number) } else { return number } } }

struct absno { static func abs(number: Int) -> Int { if number < 0 { return (-number) } else { return number 121

​Quick is just a powerful and spontaneous programming language for macOS, iOS, watchOS and tvO...  

...

Advertisement