MyLocations Tutorial 3 page : 53

I have a question for //3 if statement in didUpdateLocations()

Even thought the code is pretty straight forward since I am a new in programming is actually I have to ask this thing.

print(“(location)”)
print(“(manager.location)”)
if location == nil || location!.horizontalAccuracy > newLocation.horizontalAccuracy {

by doing this print on top of this if I see some weird stuff

  1. location is nil! and doesn’t get into the if statement until we have 2)
  2. || (OR) gets true only when the manager.location actually has a value and not when the location has a value.
  3. then the → location ← gets the value from newLocation

I have done the whole example and I have stack at that point of code.
Can you please explain how does this work?

BTW amazing work !

Regards P

The if statement works like this:

if fridgeIsEmpty OR theChickenInTheFridge > 3 days old {
  // buy a new chicken
}

If the fridge is empty we don’t have to check if the chicken is more than 3 days old, because we know there is no chicken. But if the fridge is not empty, then we do have to check the chicken.

Does that make sense? :wink:

No more coffee for me today!!! I understand completely the example and the unwraping it’s just that I need to sleep for today !!!

LOCATION : nil
LOCATION MANAGER : Optional(<+> +/- 10.00m (speed 0.00 mps / course -1.00) @ 6/22/17, 3:12:45 PM Central European Summer Time)
LOCATION : nil
location updated------------Optional(<+> +/- 10.00m (speed 0.00 mps / course -1.00) @ 6/22/17, 3:12:45 PM Central European Summer Time)
*** Done
*** Going to Geocode

I guess is time to sleep ! Thanks a lot for the fast reply

Great work !!!