Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift 2.0 Basics Swift Operators Working With Operators: Part 2

Ryan Maneo
Ryan Maneo
4,342 Points

What exactly went wrong here...

I am learning Unary operators, and it is asking me to use a NOT operator and compare this... I don't recall learning about a NOT operator and I can't find any clear documentation for it anywhere... can someone explain?

Challenge: http://prntscr.com/9hemog

What I put: http://prntscr.com/9hem6x


  • Ryan

1 Answer

Hi Ryan,

The NOT operator is an exclamation mark (!). Easiest way to explain it is with a boolean example

var isSwiftGreat : Bool;

// Yeah it is so assign true!
isSwiftGreat = true;

  print("Yeah Swift Is Great");
else if(!isSwiftGreat)
  print("Nahh Its Not");

However I didn't really need to check if swift the variable isSwiftGreat is not true (else if block) as it would only fall into that block if it wasn't true.

Just reading the question you can do something like this:

var initialScore = 8;

let totalScore = ++initialScore;

if !(10 > totalScore){

Where the !(...) is simply converting 10 is more than totalScore to either true or false. However they want you to do it a different way, just thought id show you a way without answering it and try to explain the NOT operator.