When using optional binding to unwrap a single method call (or optional chaining for a long method call chain), the syntax is clear and understandable:
if let childTitle = theItem.getChildItem()?.getTitle() {
...
}
But, when provided the variable as a parameter, I find myself either using:
func someFunction(childTitle: String?) {
if let theChildTitle = childTitle {
...
}
}
or even just redefining it with the same name:
if let childTitle = childTitle { ... }
And I've started wondering if there is a shortcut or more efficient of performing a nil
check for the sole purpose of using an existing variable. I've imagined something like:
if let childTitle { ... }
Does something like this exist, or at least an alternative to my above two interim solutions?