Learn Swift Fundamentals by preparing for Job Interview, Questions 29~ 32 For Functions
Functions in Swift are a really important topic. However, sometimes there are things that even experienced developers do not know. Here you can make your own difference. So read carefully!
29) What is function? What is the difference between function and Method?
- Function / Method is a block of statements which performs some specific task.
- Function is global whereas Method is associated with a
30) What is "
inout" parameter in Swift?
- The input arguments of a method by default are
letconstants. To change the value of input arguments the input keyword helps.
- To pass the references of the arguments to a method we use inout keyword.
31) Instance method vs Type Method?
- Methods are two types: Instance methods and Type Methods.
- Instance methods are tied up with the instance of a class. So access instance methods using object.
- Type methods are tied up with classes. Use ClassName. TypeMethod.
- Use static / class to declare Type Methods
32) What is the difference between
class func and
static func ?
- class func — can be overridden, but static func cannot be overridden.
- if you use
class type methodwith
finalkeyword, there is no difference using
static type method