Difference between type method and type instance method, etc?

后端 未结 5 532
清歌不尽
清歌不尽 2020-12-23 15:04

Note: I\'ve read the apple documentation and studied a swift book.

  1. I\'m confused on the difference between a \"type instance method\" (if such exists, corre

5条回答
  •  一整个雨季
    2020-12-23 15:52

    It is all about scopes, it defines a boundary of where and how you can use a function. A method can only be used after you initialized an object from the class. Simply to say, in order to use the method, you have to created the object first, method belongs to the object.

    But, what if you need to use a method but do not need to initiate an object, say, a global setting (ex. authorizationStatus() function in CLLocationManager for GPS coordinates authorization), you can then create a type method and simply by refer to the type name (NOT object name) and followed by the classic doc function calling.

提交回复
热议问题