0 votes
46 views
asked in Swift by
Hi

  What is the difference between function and method in swift?

1 Answer

0 votes
answered by (8.2k points)

Hi All

  As per the apple documents

Method:

Methods are functions that are associated with a particular type. Classes, structures, and enumerations can all define instance methods,

class Person {

func getUserName(){

   }

}

Function 

Functions are self-contained chunks of code that perform a specific task. You give a function a name that identifies what it does, and this name is used to “call” the function to perform its task when needed.

func numbers()->Int{

    return Int(arc4random_uniform(42))

}

Note  : Function we can call anywhere through out the app lifecycle and the same we don't need any instance 

Categories

...