Hi Alex, Why not use Swift's nil coalescing operator instead? e.g. let param2 = param2 ?? "" It avoids the if-let/else, the extra variable, and the extension.
yep! this extension is just a "nicety" for readability as you can chain things together with it such as: if someString.orEmpty().isEmpty where if you do coalescing operator you'd have to reserve to: if (someString ?? "").isEmpty neither is better or worse, just your own preference of readability. The idea for this extension method comes from Kotlin kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/is-null-or-empty.html
@@InsideiOSDev Hi Alex. Please pardon the delay getting back to you. Things have been busy, and good, here. The conventional Swift expression of isNilOrEmpty is someString?.isEmpty ?? truecertainly readability in some cases, it would help educate beginning Swift developers on Swift core language features as well as showing the value of extensions. But starting with a C-style if/else (Swift certainly can use if/else, but in this scenario it's an odd use), the beginning developer misses out on the opportunity to learn a core language feature and comes out with an idea that may lead to some odd code just because they don't understand part of the language, which is unfortunate. I hope this helps as you formulate your content and wish you the best.
true! this extension is just a "nicety" for readability as you can chain things together with it such as: if someString.orEmpty().isEmpty where if you do coalescing operator you'd have to reserve to: if (someString ?? "").isEmpty neither is better or worse, just your own preference of readability. The idea for this extension method comes from Kotlin kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/is-null-or-empty.html
Nice video! A little correction String is a struct not a class.
Thank you for the video! It’s very useful!
Cool. And extension could be extended to cover for sequences.
Hi Alex,
Why not use Swift's nil coalescing operator instead?
e.g.
let param2 = param2 ?? ""
It avoids the if-let/else, the extra variable, and the extension.
yep! this extension is just a "nicety" for readability as you can chain things together with it such as:
if someString.orEmpty().isEmpty
where if you do coalescing operator you'd have to reserve to:
if (someString ?? "").isEmpty
neither is better or worse, just your own preference of readability. The idea for this extension method comes from Kotlin kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/is-null-or-empty.html
@@InsideiOSDev Hi Alex. Please pardon the delay getting back to you. Things have been busy, and good, here.
The conventional Swift expression of isNilOrEmpty is someString?.isEmpty ?? truecertainly
readability in some cases, it would help educate beginning Swift developers on Swift core language features as well as showing the value of extensions. But starting with a C-style if/else (Swift certainly can use if/else, but in this scenario it's an odd use), the beginning developer misses out on the opportunity to learn a core language feature and comes out with an idea that may lead to some odd code just because they don't understand part of the language, which is unfortunate.
I hope this helps as you formulate your content and wish you the best.
Thanks for the video also nil coalescing operator works well let unwrappedparam2 = param2 ?? ""
true! this extension is just a "nicety" for readability as you can chain things together with it such as:
if someString.orEmpty().isEmpty
where if you do coalescing operator you'd have to reserve to:
if (someString ?? "").isEmpty
neither is better or worse, just your own preference of readability. The idea for this extension method comes from Kotlin kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/is-null-or-empty.html