Swift optional chaining doesn't work in closure

后端 未结 4 1952
孤独总比滥情好
孤独总比滥情好 2020-12-03 13:45

My code looks like this. My class has an optional var

var currentBottle : BottleLayer?

BottleLayer has a method jiggle().

4条回答
  •  心在旅途
    2020-12-03 14:30

    Letting the closure type be inferred seems to work as well.

    let clos2 = { currentBottle?.jiggle() }
    clos2() // does a jiggle
    

    But I'm pretty sure this is just the compiler assigning a type of () -> ()?

提交回复
热议问题