Soumettre la recherche
Mettre en ligne
FriendlyErrorType
•
0 j'aime
•
941 vues
naoty_bot
Suivre
ErrorTypeを使っていく上での問題点を解決する方針
Lire moins
Lire la suite
Logiciels
Signaler
Partager
Signaler
Partager
1 sur 14
Télécharger maintenant
Télécharger pour lire hors ligne
Recommandé
お申し込みを1割増やしたフォーム改善の話
お申し込みを1割増やしたフォーム改善の話
lolipopjp
OSSから学ぶSwift実践テクニック
OSSから学ぶSwift実践テクニック
庸介 高橋
Extra view @ kyobashi.swift
Extra view @ kyobashi.swift
Keisuke Tsukagoshi
おうちハック発表会 #5 家族の「ただいま」を教えてくれるキーホルダー
おうちハック発表会 #5 家族の「ただいま」を教えてくれるキーホルダー
庸介 高橋
AWS Mobile Maniacs
AWS Mobile Maniacs
akitsukada
IoTをインターネット越しで見る
IoTをインターネット越しで見る
tnoho
デジタルマーケティングとはどんな仕事か
デジタルマーケティングとはどんな仕事か
Takeru Muroya
MVPパターンによる設計アプローチ「あなたのアプリ報連相できてますか」
MVPパターンによる設計アプローチ「あなたのアプリ報連相できてますか」
U-dai Yokoyama
Recommandé
お申し込みを1割増やしたフォーム改善の話
お申し込みを1割増やしたフォーム改善の話
lolipopjp
OSSから学ぶSwift実践テクニック
OSSから学ぶSwift実践テクニック
庸介 高橋
Extra view @ kyobashi.swift
Extra view @ kyobashi.swift
Keisuke Tsukagoshi
おうちハック発表会 #5 家族の「ただいま」を教えてくれるキーホルダー
おうちハック発表会 #5 家族の「ただいま」を教えてくれるキーホルダー
庸介 高橋
AWS Mobile Maniacs
AWS Mobile Maniacs
akitsukada
IoTをインターネット越しで見る
IoTをインターネット越しで見る
tnoho
デジタルマーケティングとはどんな仕事か
デジタルマーケティングとはどんな仕事か
Takeru Muroya
MVPパターンによる設計アプローチ「あなたのアプリ報連相できてますか」
MVPパターンによる設計アプローチ「あなたのアプリ報連相できてますか」
U-dai Yokoyama
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Contenu connexe
En vedette
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
En vedette
(20)
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Skeleton Culture Code
Skeleton Culture Code
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
FriendlyErrorType
1.
FriendlyErrorType naoty
2.
3.
NSError • エラーを表すオブジェクト • 昔から使われてきた •
** NSErrorにnilを渡すことでエラーハンドリングを 簡単にサボることができる。
4.
ErrorType • エラーを表す型が実装すべきprotocol • Swift
2.0で導入された。 • ErrorTypeをthrowするメソッドを呼び出す際は do catchでエラーハンドリングする必要がある。
5.
ErrorTypeへの移行 • エラーハンドリングをコンパイル時に強制できるた めやや安全(catch内で無視することはできる)。 • Cocoaフレームワーク内のメソッドがErrorTypeを 使う形に置き換えられている。 •
アプリ独自のエラーもErrorTypeで実装すべき?
6.
ErrorTypeの問題点 • NSErrorには存在した詳細なエラー情報がない。 • localizedDescription •
localizedFailureReason • localizedRecoverySuggestion
7.
ErrorType public protocol ErrorType
{ } extension ErrorType { }
8.
FriendlyErrorType • ErrorTypeを継承したprotocol • NSErrorが持っていた基本的な情報を定義する。 •
ErrorTypeの問題点を解決するひとつの案です。
9.
FriendlyErrorType protocol FriendlyErrorType: ErrorType
{ var summary: String { get } var reason: String? { get } var suggestion: String? { get } }
10.
enum ApplicationError: FriendlyErrorType
{ case SomethingWrong case DecodeFailed([String]) var summary: String { switch self { case .SomethingWrong: return “Something wrong.” case .DecodeFailed(let fields): let failedFields = fields.joinWithSeparator(“, “) return “Failed to decode fields: (failedFields)” } } }
11.
NSErrorとの共存 • Alamofire等を使っているとNSErrorを扱う場面が まだある。 • Promise系のライブラリでエラー型を統一したい場 合、ErrorTypeとNSErrorを同じように扱いたい。 •
NSErrorを拡張してprotocolを実装することで 解決できる。
12.
extension NSError: FriendlyErrorType
{ var summary: String { return localizedDescription } var reason: String? { return userInfo[(略)] as? String } var suggestion: String? { return userInfo[(略)] as? String } }
13.
return Task<Void, [Item],
FriendlyErrorType> { … in Alamofire.request(…).responseJSON { response in switch response.status { case .Success(let value): do { let items = try decode(value) as [Item] fulfill(items) } catch DecodeError.MissingKeyPath(let keyPath) { reject(ApplicationError.DecodeFailed(keyPath.components)) } catch { reject(ApplicationError.SomethingWrong) } case .Failure(let error): reject(error) } } }
14.
まとめ • NSErrorよりErrorTypeを積極的に使おう。 • ErrorTypeを継承したprotocolでエラー情報を追加 することでErrorTypeの欠点をカバーできる。 •
NSErrorを拡張してprotocolを実装することで ErrorTypeとNSErrorの共存も可能。
Télécharger maintenant