Resolved Why is the ! before the variable in !text.isEmpty()?

Discussion in 'iOS Programming' started by chrono1081, Apr 18, 2016.

  1. chrono1081, Apr 18, 2016
    Last edited: Apr 18, 2016

    chrono1081 macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #1
    Hi guys,

    I'm working through the Big Nerd Ranch iOS/Swift book and there is a line where the code looks like this:
    Code:
     if let text = textField.text where !text.isEmpty {
    celsiusLabel.text = text
    }
    else {
    celsiusLabel.text = "???"
    }
    }
    My question is why is the exclamation point in front of the variable name? I see this occasionally in Swift code but have yet to find an explanation for it. If it is a force unwrap why is it up front?



    EDIT: I'm so dumb. Its a "not" operator. Damn Swift and its crazy !'s everywhere had me confused.
     
  2. chrono1081 thread starter macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #3
    It is but I noticed the old way of editing a title doesn't work and I can't figure out where the "Thread Tools" option is in the post you linked. I don't see it anywhere.

    EDIT: Found it. Its not very intuitive. For anyone else you have to click on your post like you're going into read it normally (not using edit mode) and there will be a tiny gear at the top of the page on the right side.
     

Share This Page