Advertisement
Larme

Untitled

Jun 20th, 2022
1,521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.68 KB | None | 0 0
  1. enum RawJSON: Codable {
  2.     case number(Double)
  3.     case string(String)
  4.     case bool(Bool)
  5. //    case dictionary([String: RawJSON])
  6. //    case array([RawJSON])
  7.     case `nil`
  8. }
  9. let RAWJSONArray = [RawJSON.string("A"),RawJSON.string("B"),RawJSON.string("C")]
  10. var arrayString : [String] = []
  11. for item in RAWJSONArray {
  12.  
  13.     if case let .string(stringValue) = item {
  14.         arrayString.append(stringValue)
  15.     }
  16.  
  17.     // OR
  18.     if case .string(let stringValue) = item {
  19.         arrayString.append(stringValue)
  20.     }
  21.     // OR
  22.     switch item {
  23.     case .string(let stringValue):
  24.         arrayString.append(stringValue)
  25.     default:
  26.         break
  27.     }
  28. }
  29.  
  30. print(arrayString)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement