Successfully reported this slideshow.
Your SlideShare is downloading. ×

What Swifty is, from Enum

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Generic forms
Generic forms
Loading in …3
×

Check these out next

1 of 51 Ad
Advertisement

More Related Content

Similar to What Swifty is, from Enum (18)

Advertisement

Recently uploaded (20)

What Swifty is, from Enum

  1. 1. What Swifty is, from Swift Enumeration freddi from HAKATA.swift
 at Fukuoka Engineers Day 2019 (20. July)
  2. 2. About Me freddi (Yuki Aki)
 iOS Engineer at LINE Fukuoka
 Organizer of HAKATA.swift
  3. 3. About HAKATA.swift Community of Swift Language
 Holding Event per 2 month
  4. 4. About HAKATA.swift
  5. 5. About HAKATA.swift 8/24 at SALT
  6. 6. What is Swifty?
  7. 7. What is Swifty? from Satoshi Hachiya - What is `Swifty`?
 https://medium.com/swift-column/what-is-swifty-34e3b2625e31
  8. 8. What is Swifty? from Swift.org - About Swift
 https://swift.org/about/ • Safe • Fast • Expressive
  9. 9. Using Expressive Code is one of Swifty? What is Swifty?
  10. 10. Only Expressive Code is Swifty? What is Swifty?
  11. 11. Expressive Code 
 with using Swift feature is Swifty! What is Swifty?
  12. 12. Enumeration in Swift
  13. 13. Swift Enumeration is one of way to make expressive code Enumeration in Swift
  14. 14. Enumeration in Swift enum Selection { case yes case no }
  15. 15. Enumeration in Swift let selection: Selection = Selection.yes enum Selection { case yes case no }
  16. 16. • Swift Enumeration is expressive! • Type Inference in Enumeration • Associated Values in Enumeration Enumeration in Swift
  17. 17. Type Inference in Enumeration
  18. 18. Type Inference in Enumeration let selection: Selection = Selection.yes enum Selection { case yes case no }
  19. 19. Type Inference in Enumeration let selection: Selection = .yes enum Selection { case yes case no }
  20. 20. Type Inference in Enumeration
  21. 21. Associated Values in Enumeration
  22. 22. Let’s make Type • Representing the result of REST API Associated Values in Enumeration
  23. 23. Associated Values in Enumeration enum APIResult { case success case error }
  24. 24. But, we have some situation at using REST API • What Error Returned? • Validation Error? • Authorization Error? Associated Values in Enumeration
  25. 25. Associated Values in Enumeration enum APIResult { case success case validationError case authError }
  26. 26. Let’s use Associated Values to represent situations Associated Values in Enumeration
  27. 27. Associated Values in Enumeration enum APIResult { case success case error }
  28. 28. Associated Values in Enumeration enum APIResult { case success case error(Error) }
  29. 29. Associated Values in Enumeration let result: APIResult = .success enum APIResult { case success case error(Error) }
  30. 30. Associated Values in Enumeration let result: APIResult = .error(ValidationError()) enum APIResult { case success case error(Error) } let result: APIResult = .success
  31. 31. Associated Values in Enumeration • Each case can have values Associated Values in Enumeration
  32. 32. Let’s make APIResult More Generic Associated Values in Enumeration
  33. 33. Associated Values in Enumeration enum APIResult { case success case error(Error) }
  34. 34. Associated Values in Enumeration enum APIResult<SuccessType> { case success(SuccessType) case error(Error) }
  35. 35. Associated Values in Enumeration func getXXX(result: APIResult<SomeData>) { switch result { case .success(let data): ... case .error(let error): ... } }
  36. 36. Optional in Swift
  37. 37. Enumeration in Swift
  38. 38. Swift Enumeration is Expressive!
  39. 39. let selection: Selection = .yes enum Selection { case yes case no } Swift Enumeration is Expressive!
  40. 40. let result: APIResult = .error(ValidationError()) enum APIResult { case success case error(Error) } let result: APIResult = .success Swift Enumeration is Expressive!
  41. 41. Swift Enumeration is Expressive! enum APIResult<SuccessType> { case success(SuccessType) case error(Error) }
  42. 42. Why expressive is great?
  43. 43. To be Expressive Helps our coding life Why expressive is great?
  44. 44. Why expressive is great?
  45. 45. Why expressive is great? enum APIResult { case success case error(Error) }
  46. 46. Why expressive is great? let result: APIResult = .error(ValidationError()) enum APIResult { case success case error(Error) }
  47. 47. Why expressive is great? enum ValidationError: Error { case nameIsInvalid case idIsInvalid } let result: APIResult = .error(ValidationError())
  48. 48. Expressive is one of Swifty
 Expressive is great!
  49. 49. Swifty and Enumeration
  50. 50. Thank you for listening!
  51. 51. 8/24 at SALT

×