Xcode Screenshot

Objective-C is an extremely verbose language, and there’s no need to add to the redundancy with unnecessary code to toggle a boolean.

You can simply toggle a boolean’s value like this:


theBool = !theBool;

Sounds like CS 101, right?

I came across this code in a popular open-source project last night:


if (power) {
  power = false;
} else {
  power = true;
}

Which can be refactored to one simple statement:


power = !power;

This also works in other C-influenced languages, such as JavaScript.

Code simple, my friends.

 App Development, Development

, , , , ,


Matthew's Blog
Home   Blog   LinkedIn   Contact Me
Connect on LinkedIn, Google+,
Current focus: App & Web Development
Preferred Environments: OS X, iOS, Xcode, Sublime Text
Current skills: SWIFT, Objective-C, iOS SDK, CoreData, CoreAudio, JavaScript, HTML5, CSS, Wordpress
Degree: Bachelors of Science in Computer Information Systems Technology
from PURDUE University


© Website by Matthew Fecher
Denver, Colorado, USA.

top