Example of a Computed Property

I am fairly new to computed properties and am trying to recongnize them in code samples... I came accross this in one of the tutorials I am learning on URLSession. Would this var method: String property be a computed property?


var method: String {
      
      switch self {
         
      case .getPublicGists():
         return "GET"
         
      }
   
   }


Thanks!

Answered by Claude31 in 333665022

Yes, it is a computed property. When .getPublicGists() can be isntantiated as self, method is set to "GET"


What is the type of self ?

Accepted Answer

Yes, it is a computed property. When .getPublicGists() can be isntantiated as self, method is set to "GET"


What is the type of self ?

The type of self is the enum GistRouter...


enum GistRouter {

/// some properties like URL string, etc.

   var method: String {
      
      switch self {
         
      case .getPublicGists():
         return "GET"
         
      }
   }
}
Example of a Computed Property
 
 
Q