Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
SwiftでのError Handlingを学び直す!
Search
Yutaka
August 13, 2016
Programming
830
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SwiftでのError Handlingを学び直す!
Swiftビギナーズ勉強会 第16回 2016/08/13
Yutaka
August 13, 2016
Transcript
42 slides
SwiftでのError Handlingを 学び直す! Swiftビギナーズ勉強会 第16回 多鹿豊 1
目次 - 自己紹介 - Error Handlingとは? - SwiftでのError Handlingの書き方 -
Swift3.0に向けて 2
目次 - 自己紹介 - Error Handlingとは? - SwiftでのError Handlingの書き方 -
Swift3.0に向けて 3
自己紹介(personal) - 多鹿豊(タジカユタカ) - @taji-taji - Qiita, GitHub - Swift暦:9ヶ月半
4
- アプリ作ってます - 観葉植物が好き - 最近Vaporで遊んで ます 自己紹介(hobby) 5
自己紹介(works) - ウェルスタイル株式会社 - 家族限定SNS 「wellnote」を開発・運営 - iOSエンジニア - たまにPHP
- ごく稀にrails - 他、AWSとか 6
目次 - 自己紹介 - Error Handlingとは? - SwiftでのError Handlingの書き方 -
Swift3.0に向けて 7
Error Handlingとは? Error handling is the process of responding to
and recovering from error conditions in your program. 引用:The Swift Programming Language (Swift 2.2): Error Handling 8
Error Handlingとは? エラーが生じた際に、エラーの内容に応じて適 切にエラー状態を回復させる処理を行うこと →例外処理・Exception Handlingみたいなもの 9
目次 - 自己紹介 - Error Handlingとは? - SwiftでのError Handlingの書き方 -
Swift3.0に向けて 10
SwiftでのError Handlingの書き方 11
例:ポケモントレーナーがポケモンを捕まえる 12
例:ポケモントレーナーがポケモンを捕まえる 13 実際のゲームの挙動とは 異なるのでご了承ください m(_ _)m
成功失敗をBoolで返す 14
15 成功失敗をBoolで返す
16 成功失敗をBoolで返す - true or falseでしか処理を分けることが できない →falseの時の失敗の仕方によって処理を 分けたい
場合によって返す数値を変えてみる 17
場合によって返す数値を変えてみる 18
場合によって返す数値を変えてみる 19
場合によって返す数値を変えてみる 20 一応処理を分けることができた が、 -1 とか 1 とか、なんのこっちゃ分からない
もっと綺麗に書けますよ 21
エラーを定義 22
エラーを定義 - ErrorTypeプロトコルに準拠した列挙型でエ ラーを定義する 23
エラーを定義 - ErrorTypeプロトコル - エラーの値として扱われることを明示的に表す 24
エラーを投げる 25
throws, throw 26
throws, throw 27 関数名・メソッド名の()の後ろに書く ことで、エラーを投げる可能性があ ることを宣言。 必ずエラーを投げないといけない わけではない。
throws, throw 28 throwで定義したエ ラーを投げる
throws, throw 29
エラーを受け取って処理 30
31 エラーを受け取って処理
32 do-catch構文
33 try do ブロック内でエラーを投げる 可能性のあるメソッドを try で実 行する。
34 エラーの内容を それぞれ catch catch
いったんまとめ 35 • エラーを投げる可能 性のある関数・メソッ ド・Initializerはthrows をつけて定義 • throwでエラーを投げ る
列挙型でエラーの定義 • ハンドリングには do-catch構文を使用 • doブロックの中でtry • catchブロックでエ ラーをキャッチ
いったんまとめ 36 • エラーを投げる可能性の ある関数・メソッド ・Initializerはthrowsを つけて定義 • throwでエラーを投げる 列挙型でエラーの定義
• ハンドリングには do-catch構文を使用 • doブロックの中でtry • catchブロックでエ ラーをキャッチ
いったんまとめ 37 • エラーを投げる可能 性のある関数・メソッ ド・Initializerはthrows をつけて定義 • throwでエラーを投げ る
列挙型でエラーの定義 • ハンドリングには do-catch構文を使用 • doブロックの中でtry • catchブロックでエラーを キャッチ
目次 - 自己紹介 - Error Handlingとは? - SwiftでのError Handlingの書き方 -
Swift3.0に向けて 38
Swift3.0に向けて - ErrorType→ErrorProtocol - SE-0006 - 列挙型の値をlowerCamelCaseに - API Design
Guidelines 39
Swift3.0に向けて 40 Swift 2.2 Swift 3.0
今回触れなかった内容 - エラーの伝播 - try? - try! 41
ご清聴ありがとうございました 42
More Decks by Yutaka
See All by Yutaka
SwiftUI で複数のアラート表示を管理する
tajitaji
0
150
Swift 6 の地味な (?) アップデート
tajitaji
1
450
2018.01.19 すくすく子育てエンジニア Meetup #1
tajitaji
1
2.2k
mlmodel のコンパイル
tajitaji
0
1.9k
統計・マーケ・R/Python・機械学習 Meetup! #2 2017.10.11
tajitaji
0
210
Vapor プロジェクトの開発に使えそうなツールの紹介
tajitaji
0
530
Server Side Swift, Vapor を触ってみた
tajitaji
0
2.1k
Other Decks in Programming
See All in Programming
オーケストレーション記述言語 Katari
yukikurage
0
260
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
340
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
340
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
580
SODA - FACT BOOK(JP)
sodainc
1
40k
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
240
小さなアプリを作って公開するまで
onozaty
0
180
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
150
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
330
GraphQL の onError と Nullability のこれから
quramy
0
220
Kotlin Fest 2026: Kotlin コンパイラに Contribute してみよう! - Kotlin/Wasm で深い再帰を書けるようにした話
ternbusty
1
210
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
350
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
480
Speed Design
sergeychernyshev
33
2.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
610
Between Models and Reality
mayunak
4
580
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
570
How to Talk to Developers About Accessibility
jct
2
620
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
370
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Heart Work Chapter 1 - Part 1
lfama
PRO
11
37k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.8k
How GitHub (no longer) Works
holman
316
150k