Guard vs if let

90 views Asked by At
guard let json = try? NSJSONSerialization.JSONObjectWithData(data!,
      options: []) as? [String: AnyObject] else {
        print("Nil data received from fetchAllRooms service")
        return
    }

In the above code I am unable to understand what is the significance of

  1. "try?": Is the "try?" here means the whole code after try will be under try block (same as try catch as in other language?)

  2. "as?" : It is for typecasting I guess. but why this "?", after as?

How can I replace the above code with if-let?

0

There are 0 answers