WhiteTherewasproblem
WhiteTherewasproblem

Reputation: 170

In Swift, what's the difference between type Int {get set} and Type Int?

For example:

    var someData:Int {
    get {
        return 5
    }

    set {

    }
}

    lazy var data2 = {return 5}()

    var data = 5

In the code above, someData and data2 are inferred as Int { get set } and data is inferred as Int.

By the way, was data2 declared from the returned value of a closure? It something like {}() called a closure? I thought closure is something like

{
... in

    return ...
}

Upvotes: 0

Views: 46

Answers (1)

Sulthan
Sulthan

Reputation: 130172

{ ... } with appended () is just a closure that is immediately being called. It could also be

let data2 = { ... in
    return ...
}()

data2 is not inferred as get set. get and set denote a computed property while data2 is a stored property.

Upvotes: 1

Related Questions