[3/10] Who is your coding partner?
Mine is my 7 months old kitty Lucy (aka Lucy.js or Lucy Belle) 🐱. Every time I’m on my laptop she likes to take a peek and see what I am working on 👩🏻💻
Today was Day 3 of the #100daysofswift challenge and we reviewed things like operator overloading, switch statements, and more.
From all operators that Swift has the one who caught my eye 😯 was the Nil-Coalescing Operator because it was my first time ever hearing about it.
The nil-coalescing operator (a ?? b) unwraps an optional (a) if it contains a value, or returns a default value (b) if a is nil 🙅🏻♀️. The a) is always of an optional type. The b) must match the type that is stored inside (a).
The nil-coalescing operator is written like the code below ⬇️
a != nil ? a! : b
The code above uses the ternary conditional operator and forced unwrapping (a!) to access the value wrapped inside (a) when (a) is not nil, and to return (b) otherwise 🔄. The nil-coalescing operator provides a more elegant way to encapsulate this conditional checking and unwrapping in a concise and readable form ✔️
Pretty interesting right? 😉 Check it out for yourself and see how this can improve the code you write.
Have a lovely week 🌸 ...
Follow 👉🏻 @codewithmemes for more updates like this .
❤️❤️Don’t forget to double tap ❤️❤️
👬Tag your friends.
🔔Turn on post notifications for more updates.
📩Message @codewithmemes if you have memes,funny video, jokes and I will upload and give credit. ...