What does this mean? Variable declared followed by a block without assignment

前端 未结 3 2102
梦毁少年i
梦毁少年i 2021-01-25 12:54

Noob Swift question--I can\'t figure out what this means in Swift:

public var currentTime: NSTimeInterval? {
    return self.audioPlayer?.currentTime
}
         


        
3条回答
  •  情书的邮戳
    2021-01-25 13:43

    It is the same as:

    public var currentTime: NSTimeInterval? {
        get { return self.audioPlayer?.currentTime }
    }
    

    When your computed property only has a get, you can omit the word get and the curly brackets.

    From the swift guide:

    You can simplify the declaration of a read-only computed property by removing the get keyword and its braces:

提交回复
热议问题