  or variable, as part of a single action.
 
  */
-func parseInt(_ string: String) -> (isInteger: Bool, value: Int) {
+
+func parseInt1(_ string: String) -> (isInteger: Bool, value: Int) {
     let possibleNumber = Int(string)
-    /* Alternative Unwrapping and Assign method */
-    /*
     if possibleNumber != nil {
         let actualNumber = possibleNumber!
         return (true, actualNumber)
     } else {
         return (false, 0)
     }
-     */
+}
+
+/*:
+ 
+ The two lines for checking nil and unwrapping could be merged as one line by
+ **optional binding**, like:
+ 
+ */
+
+func parseInt(_ string: String) -> (isInteger: Bool, value: Int) {
+    let possibleNumber = Int(string)
     if let actualNumber = possibleNumber {
         return (true, actualNumber)
     } else {

}
parseInt("12")
parseInt("XD")
//:
//: The `if` statement in `parseInt(_:)` could be read as
//:
//: “If the optional Int returned by `Int(possibleNumber)` contains a value,
//: set a new constant called `actualNumber` to the value contained in the optional.”
//:
//: > Try to "option+click" on `possibleNumber` and `actualNumber` to see their types.

func squareFloat(_ string: String) -> String? {
    guard let floatNumber = Float(string) else {

}
squareFloat("16.0")
squareFloat("A")

/*:
 
 The `optional binding` could be chained together, like:
 
 */

func getAnswer() -> String? {
    let someOptionalString: String? = "42"
    if let concreteString = someOptionalString, let answer = Int(concreteString) {
        return "The answer is \(answer)."
    } else {
        return nil
    }
}
getAnswer()!

func stringPower(base: String, exponent exp: String) -> String? {
    guard let baseNumber = Int(base), let expNumber = Int(exp) else {
        return nil
    }
    var result = 1
    for _ in 0..<expNumber {
        result *= baseNumber
    }
    return String(result)
}
stringPower(base: "2", exponent: "5")
stringPower(base: "2", exponent: "B")

/*:

