Tim Nuwin Tim Nuwin - 1 month ago 12
Swift Question

How do I return if let doesn't unwrap, using legacy swift

The guard line throws this error


using legacy swift: Initializer for conditional binding must have
Optional type, not 'UIView'


private func animateDismissal(context: UIViewControllerContextTransitioning) {

guard let containerView = context.containerView() else {
return
}
...


How do I return if let doesn't unwrap?

Answer

context.containerView() is not optional, so it cant be nil. So no need to guard or unwrap it.