1

In the latest Swift doc it is mentioned that

Marking a closure with @escaping means you have to refer to self explicitly within the closure.

and in the following method on UIView

animate(withDuration duration: TimeInterval, animations: @escaping () -> Swift.Void, completion: ((Bool) -> Swift.Void)? = nil)

The @escaping is only for the first closure parameter, but still in the second closure I'm required to use self or else it gives the following error

enter image description here

setUpButton() is a method in my class

Why is this so? Do I have to use self in all the closures or just the ones marked with @escaping.

Rahul
  • 11
  • 1
  • 2
    You are obligated to use self in escaping closures only. But optional closures are implicitly escaping whereas non-optional closures are implicitly non-escaping and can be marked as escaping with the `@escaping` keyword. – deadbeef Jun 27 '17 at 14:54
  • Related: https://stackoverflow.com/questions/43200857/trouble-with-non-escaping-closures-in-swift-3. – Martin R Jun 27 '17 at 15:01
  • 1
    Thanks @deadbeef that really helped! – Rahul Jun 27 '17 at 15:10
  • thanks @deadbeef for the great point you touched! – Okhan Okbay Aug 03 '18 at 20:40

0 Answers0