Ad
  • Custom User Avatar

    @minnepicker THank you so much sensei!

  • Custom User Avatar

    hi bridgecoder, Swift has a concept called optionals. These are used when an object may or may not exist. For example, if I try to initialize a digit with a string that contains an Int (like this: Int("5")), everything is fine. However, if I try to use an invalid string (like this: Int("Cow")), Swift can't make an integer out of it so it returns nil. Because this initializer might return nil, it is optional. Swift can't make a comparison on an optional object. We have to "unwrap" it and see if a value exists or not. There are several ways to unwrap an optional in Swift. The least safe way is to force unwrap it using "!". The "!" in this context is basically saying that you guarantee the optional will have a value and not nil. If it doesn't have a value, your program will crash.

  • Custom User Avatar

    hey pal, Im new to swift, could you please explain this step: if Int("(digit)")! < 5
    Especially what ! does? I come from Python bg so I tried using <= but didnt work so...Please do let me know

  • Custom User Avatar

    I chuckled when I saw this; very clever 😀