Boolean is one of the most frequently used and simplest data type in any programming language.It is common to want to toggle the state of the boolean variable. So, we normally do it like this,
The above approach is common but there will be cases where the boolean value should be toggled frequently. Explicitly assigning the boolean to true or false can be error prone. In Swift, we can use the toggle() method to toggle the value of a boolean.
Though it is simple, it will be very beneficial in cases which involves complex data structures like,
Follow me on Twitter. Have any queries? Feel free to DM me.
Like our articles? Support us!