Post B4xaheSfSdg0Dn53Zo by tewha@appdot.net
(DIR) More posts by tewha@appdot.net
(DIR) Post #B4xaheSfSdg0Dn53Zo by tewha@appdot.net
0 likes, 0 repeats
One thing I appreciate about Swift is that something like this works:let searchText = searchText // RHS is a propertyif !searchText.isEmpty, let parts = split(searchText) {}Though I wish this would work, even if the original searchText was non-optional:if let searchText = searchText, !searchText.isEmpty, let parts = split(searchText) {}Or even:if let searchText, !searchText.isEmpty, let parts = split(searchText) {}I'm not sure how else to temporarily scope the expression. #Swift
(DIR) Post #B4xahefmfsAUsTDX1M by tewha@appdot.net
0 likes, 0 repeats
I mean… is this terribly abusive?Again, the RHS searchText is a property, so this is avoiding repeated evaluation.if let searchText = Optional(searchText), !searchText.isEmpty, let parts = ChordUtility.split(searchText) {} #Swift
(DIR) Post #B4xahestt6ezX9M0Su by shadowfacts@social.shadowfacts.net
0 likes, 0 repeats
@tewha no need to wrap it in the optional, you can pattern match a non-optional with if case let
(DIR) Post #B4xahflUc8KSGStbYe by tewha@appdot.net
0 likes, 0 repeats
I'm going to say this as a general principle:I think if let thing = otherThing, thing.condition() should be valid, whether otherThing is optional or not.Nothing really replaces it. guard is opposite in that it scopes it for the rest of the function. I want to scope it only for the if's warm em-braces.Apologies for the pun, but @josh made it happen somehow. #Swift