Distinction in Swift between uppercase “Self” and lowercase “self”

前端 未结 6 1023
心在旅途
心在旅途 2020-12-07 10:53

While playing in a Swift playground I noticed that Self, with capital \"S\", is available along with the lowercase self. Is there any difference be

6条回答
  •  春和景丽
    2020-12-07 11:28

    I understand Self as a type name(class name for example) and self as an instance of a class/struct , for example:

    struct Person {
         static var documentNumner = "9484930"
         var name: String
         var computedFullName: String {
            return ("\(self.name) with document number: \(Self.documentNumner)")
    
        }
    }
    

    You can't use self with a static property but you can use Self

提交回复
热议问题