0

I just want to confirm that UIAlertAction's handler is a non-escaping lambda function?

I did ctrl + right-click and looked up the UIAlertAction definition and it does not look escaping by default. Which means I should do

weak var wself = self 

and use wself instead of self inside all UIAlertAction completion blocks?

Under UIKit>UIAlertController I see

open class UIAlertAction : NSObject, NSCopying {


public convenience init(title: String?, style: UIAlertAction.Style, handler: ((UIAlertAction) -> Void)? = nil)

where the handler does not show @escaping

aman
  • 499
  • 8
  • 18
  • It _is_ an escaping closure. I don't know why you can't see it from the definition though. Maybe it's because it's from Objective-C. – Sweeper Feb 18 '19 at 17:00
  • 1
    Optional closures are all implicitly escaping. See [here](https://www.jessesquires.com/blog/why-optional-swift-closures-are-escaping/) – Sweeper Feb 18 '19 at 17:04
  • thanks @sweeper. if you want to post this as the answer I'll accept it. – aman Feb 20 '19 at 15:23

1 Answers1

1

UIAlertAction handler is escaping

because Optional closures are all implicitly escaping (thanks to @sweeper)

aman
  • 499
  • 8
  • 18