Learn Swift Fundamentals by preparing for Job Interview, Questions 29~ 32 For Functions
2 min readApr 12, 2022
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?
Answer:
- Function / Method is a block of statements which performs some specific task.
- Function is global whereas Method is associated with a
Class
andStructure
.
30) What is "inout"
parameter in Swift?
- The input arguments of a method by default are
let
constants. 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
?
Answer:
- class func — can be overridden, but static func cannot be overridden.
#Tips
- if you use
class type method
withfinal
keyword, there is no difference usingstatic type method