Guest User

Untitled

a guest
Apr 26th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import Foundation
  2.  
  3.  
  4. class BoolEncoder: SingleValueEncodingContainer {
  5. var codingPath: [CodingKey]
  6. private(set) var value: Bool?
  7.  
  8. init() {
  9. codingPath = []
  10. }
  11.  
  12. func encodeNil() throws {
  13. value = nil
  14. }
  15.  
  16. func encode(_ value: Bool) throws {
  17. self.value = value
  18. }
  19.  
  20. func encode(_ value: String) throws {
  21. fatalError("\(type(of: self)) only supports bools.")
  22. }
  23.  
  24. func encode(_ value: Double) throws {
  25. fatalError("\(type(of: self)) only supports bools.")
  26. }
  27.  
  28. func encode(_ value: Float) throws {
  29. fatalError("\(type(of: self)) only supports bools.")
  30. }
  31.  
  32. func encode(_ value: Int) throws {
  33. fatalError("\(type(of: self)) only supports bools.")
  34. }
  35.  
  36. func encode(_ value: Int8) throws {
  37. fatalError("\(type(of: self)) only supports bools.")
  38. }
  39.  
  40. func encode(_ value: Int16) throws {
  41. fatalError("\(type(of: self)) only supports bools.")
  42. }
  43.  
  44. func encode(_ value: Int32) throws {
  45. fatalError("\(type(of: self)) only supports bools.")
  46. }
  47.  
  48. func encode(_ value: Int64) throws {
  49. fatalError("\(type(of: self)) only supports bools.")
  50. }
  51.  
  52. func encode(_ value: UInt) throws {
  53. fatalError("\(type(of: self)) only supports bools.")
  54. }
  55.  
  56. func encode(_ value: UInt8) throws {
  57. fatalError("\(type(of: self)) only supports bools.")
  58. }
  59.  
  60. func encode(_ value: UInt16) throws {
  61. fatalError("\(type(of: self)) only supports bools.")
  62. }
  63.  
  64. func encode(_ value: UInt32) throws {
  65. fatalError("\(type(of: self)) only supports bools.")
  66. }
  67.  
  68. func encode(_ value: UInt64) throws {
  69. fatalError("\(type(of: self)) only supports bools.")
  70. }
  71.  
  72. func encode<T>(_ value: T) throws where T : Encodable {
  73. fatalError("\(type(of: self)) only supports bools.")
  74. }
  75. }
Add Comment
Please, Sign In to add comment