let a = age { print(" \(a)ࡀͰ͢ʂ") } else { print("ྸ͋Γ·ͤΜ") } // if-let + ݅ذ let age: Int? = 20 if let a = age, a >= 20 { print(" \(a)ࡀͰɺਓͯ͠·͢ʂ") }
check response guard let data = responseData else { print("response data is empty") return nil } guard let id = data["id"] as? String else { print("user id is not found.") return nil } return id } ωοτϫʔΫܦ༝Ͱऔಘͨ͠σʔλΛύʔε͢Δ
let (age, name): print("user is age: \(age), name: \(name)") case (let age, "hogefuga"): print("user is age: \(age), name: hogefuga") case (20, let name): print("user is age: 20, name: \(name)") case (20, "hogefuga"): print("user is age: 20, name: hogefuga") case let (age, name, gender): print(“Ϛον͠·ͤΜ") default: print("something else") }
case nilResponse } switch error { case .authError: print("ೝূʹࣦഊ͠·ͨ͠") case .unexpectedData: print("ෆਖ਼ͳσʔλͰ͢") case .unknownError: print("Α͘Θ͔Γ·ͤΜ͕ΤϥʔͰ͢(^q^)") case .nilResponse: print("Ϩεϙϯε͕ۭͬΆͰ͢") case .timeout: print("αʔόʔ͔ΒԠ͕͋Γ·ͤΜ") }
case nilResponse } switch error { case .authError: print("ೝূʹࣦഊ͠·ͨ͠") case .unexpectedData: print("ෆਖ਼ͳσʔλͰ͢") case .unknownError: print("Α͘Θ͔Γ·ͤΜ͕ΤϥʔͰ͢(^q^)") case .nilResponse: print("Ϩεϙϯε͕ۭͬΆͰ͢") case .timeout: print("αʔόʔ͔ΒԠ͕͋Γ·ͤΜ") }
case nilResponse } switch error { case .authError: print("ೝূʹࣦഊ͠·ͨ͠") case .unexpectedData: print("ෆਖ਼ͳσʔλͰ͢") case .unknownError: print("Α͘Θ͔Γ·ͤΜ͕ΤϥʔͰ͢(^q^)") case .nilResponse: print("Ϩεϙϯε͕ۭͬΆͰ͢") case .timeout: print("αʔόʔ͔ΒԠ͕͋Γ·ͤΜ") } default͕ͳ͍ʂ
▸ Ͱ͖ΕܕมΛߦ͏ίʔυ͕ͳ͍ͷ͕ཧͰ͋ΔͷͰ͏͜ͱ গͳ͍(͔?) let nyantyu: Animal = Cat(name: "nantyu") switch nyantyu { case let a as Cat: print("ೣͰͨ͠(?)") a.burk() case is Dog: print("ݘͰ͢") default: print("ಈͰ͋Γ·ͤΜ") }