Is there is a way to have guard automatically return without needing to actually write it out every single time, e.g:
guard let url = self.webView.url else { return }
guard let componentDict = URLComponents(string: url.absoluteString)?.dict else { return }
guard let id = componentDict["v"] else { return }
guard let idUrl = URL(string: baseUrl + id) else { return }
In the case where I actually need to do something in addition to return, I would include the else { return } bit with my extra handling.
Its not a huge bother, but it would be a nice thing to have.
guardstatement is typed withelsemust be, there is no shortcut for this but you can useif..letto avoidelsestatement.Or combine this related variables statement with single
guardstatement