Posts

Showing posts from March 3, 2019

Difference between computed property and property set with closure

Image
47 22 I'm new to Swift. What is the difference between a computed property and a property set to a closure? I know a computed property gets recalculated each time. Is it different for the closure? i.e. Closure: var pushBehavior: UIPushBehavior = { let lazilyCreatedPush = UIPushBehavior() lazilyCreatedPush.setAngle(50, magnitude: 50) return lazilyCreatedPush }() Computed: var pushBehavior: UIPushBehavior { get{ let lazilyCreatedPush = UIPushBehavior() lazilyCreatedPush.setAngle(50, magnitude: 50) return lazilyCreatedPush } } swift computed-properties share | improve this question edited J