Upgrade to Pro — share decks privately, control downloads, hide ads and more …

いいから `!` を使え! / Shut up and use `!` !

Elvis Shi
February 26, 2021

いいから `!` を使え! / Shut up and use `!` !

Elvis Shi

February 26, 2021
Tweet

More Decks by Elvis Shi

Other Decks in Programming

Transcript

  1. } var employedBy = "YUMEMI Inc." var job = "iOS

    Tech Lead" var favoriteLanguage = "Swift" var twitter = "@lovee" var qiita = "lovee" var github = "el-hoshino" var additionalInfo = """ อޢͨ͠ೣ͕ͷൃ৘ظʹಥೖͯ݁͠ߏେม """ final class Me: Developable, Talkable {
  2. ͜ͷίʔυͬͯɺ҆શʁ func doSomething() { guard let appDelegate = UIApplication .shared.delegate

    as? AppDelegate else { return } // do something with appDelegate }
  3. ͜ͷίʔυͬͯɺ҆શʁ func doSomething(with data: Data) { do { let decoder

    = JSONDecoder() let response = try decoder.decode(Response.self, from: data) // do something with response } catch { debugPrint(error) return } }
  4. ੲɺ0CK$͔Β4XJGUʹҠߦͨ࣌͠ͷ࿩˞ w αʔό͔Βը૾σʔλͱදࣔαΠζΛऔಘ͢Δॲཧ͕͋ͬͨ w αΠζσʔλ͸෯ߴͦ͞ΕͧΕ0CK$ͷίʔυͰintValueͰऔಘͯͨ͠ w 4XJGUԽ͢Δͱ͖͸Կ΋ߟ͑ͣʹas? Int ?? 0Ͱॲཧͯͨ͠

    w ϦϦʔεޙɺҰ෦ͷը૾ͷΈΞεϖΫτൺ͕มΘͬͯ͠·ͬͨࣄ͕݅ൃੜ w ௐࠪͨ͠Βɺαʔό͔Βؼ͖ͬͯͨσʔλ͕ͳ͔ͥจࣈྻσʔλͩͬͨͨ Ίɺ0CK$͸ࣗಈม׵ͯ͘͠Ε͕ͨ4XJGU͸ܕʹݫ͍ͨ͠Ίࣗಈม׵ͯ͘͠ Εͣɺ?? 0ʹΑͬͯ0͕୅ೖ͞Εͨ w ෯0ߴ͞0ͷ৔߹͸σϑΥϧταΠζͰදࣔ͢Δॲཧ͕͋ͬͨͨΊɺςε τσʔλͰಈ࡞֬ೝ͢Δͱ͖͸શ͘ؾ͔ͮͳ͔ͬͨ ˞࣮࿩Ͱ͢
  5. ͜ͷίʔυͷํ͕ɺ҆શ func doSomething() { let image = UIImage(named: "ImageName")! //

    do something with image } όϯυϧʹೖͬͯͳ͍ͱ͍͚ͳ͍͸ͣͷ 
 ը૾Ϧιʔε͔ͩΒɺ ສ͕Ұೖͬͯͳ͔ͬͨΒͦΕ͸όάͳͷͰ ಈ࡞֬ೝͰΫϥογϡͯ͘͠Εͨํ͕ 
 ؾ෇͖΍͍͢
  6. ͜ͷίʔυͬͯɺ҆શʁ func doSomething() { guard let appDelegate = UIApplication .shared.delegate

    as? AppDelegate else { return } // do something with appDelegate }
  7. ͜ͷίʔυͷํ͕ɺ҆શ func doSomething() { let appDelegate = UIApplication.shared.delegate as! AppDelegate

    // do something with appDelegate } ϓϩδΣΫτͷ࡞Γ͕ 
 ͜ͷΑ͏ʹͳͬͯΔ͸ͣͳͷͰɺ ສ͕Ұ͜ΕͰμ΢ϯΩϟετͰ͖ͳ͔ͬͨΒ ઈରϓϩάϥϜ͕Կ͔ؒҧͬͯΔ͸͔ͣͩΒɺ ಈ࡞֬ೝͰΫϥογϡͯ͘͠Εͨํ͕ ؾ෇͖΍͍͢
  8. ͜ͷίʔυͬͯɺ҆શʁ func doSomething(with data: Data) { do { let decoder

    = JSONDecoder() let response = try decoder.decode(Response.self, from: data) // do something with response } catch { debugPrint(error) return } }
  9. ͜ͷίʔυͷํ͕ɺ҆શ func doSomething(with data: Data) { do { let decoder

    = JSONDecoder() let response = try decoder.decode(Response.self, from: data) // do something with response } catch { assertionFailure("\(error)") return } } ԾʹαʔόͷσʔλͱҰக͠ͳ͔ͬͨΒ BTTFSUJPO'BJMVSFʹΑͬͯ σόοάϏϧυ͚ͩΫϥογϡͯ͠ 
 όάΛૣظൃݟ͠ɺ ຊ൪ͷϦϦʔεϏϧυʹ͸Өڹͳ͠ɻ ʢ΋ͪΖΜ͜͜ͰߋʹΤϥʔΞϥʔτΛ 
 Ϣʔβʹදࣔͤͨ͞Βͳ͓ྑ͠ʣ
  10. ͜ͷίʔυ͸ɺ͕͢͞ʹ҆શͰ͸ͳ͍ func doSomething(with data: Data) { let decoder = JSONDecoder()

    let response = try! decoder.decode(Response.self, from: data) // do something with response } ສ͕Ұαʔόଆ͕όάΛى͜Γ 
 ຊདྷͷ࢓༷ͱ͸ҧ͏ܕͷϨεϙϯε͕ 
 ؼ͖ͬͯͨΒ 
 ΞϓϦ͕ଈΫϥογϡ͢ΔͷͰ 
 ྲྀੴʹྑ͘ͳ͍