Learn Swift Fundamentals by preparing for Job Interview, Questions 29~ 32 For Functions

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 Class and Structure.
Difference between Function and Method

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.
Without `inout`, you cannot change method argument
With `inout`, you can change method argument

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
Swift Type Methods

32) What is the difference between class func and static func ?

  • class func — can be overridden, but static func cannot be overridden.
Difference between class method and static method
  • if you use class type method with final keyword, there is no difference using static type method

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
KD Knowledge Diet

KD Knowledge Diet

2.4K Followers

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!