1

Currently, I'm trying to use Swift's codable protocol to add and read custom objects to and from Firebase's database. I've been following the instructions in these docs. However, when I try to write to the database, I'm getting an error "FIRInvalidArgumentException: Nested arrays are not supported". But aren't they supported? I saw another post on here from a couple of years ago that addressed a similar issue but I don't understand what I did wrong here.

These are the Swift struct representations that implement Codable:

struct List: Codable {

    var title: String
    var date: String
    var description: String
    var data: [SectionHeaders: Array<Item>] = [
        .produce: [],
        .seafood: [],
        .meat: [],
        .deli: [],
        .bakery: [],
        .pantry: [],
        .dairy: [],
        .frozen: [],
        .other: []
    ]
    
    enum CodingKeys: String, CodingKey {
        case name
        case date
        case description
        case data = "items"
    }

struct Item: Codable {
    var name: String?
    var quantity: String?
}

enum SectionHeaders: Int, Codable {
    case produce = 0, seafood, meat, deli, bakery, pantry, dairy, frozen, other, total
    
    enum CodingKeys: String, CodingKey {
        case produce = "produce"
        case seafood = "seafood"
        case meat = "meat"
        case deli = "deli"
        case bakery = "bakery"
        case pantry = "pantry"
        case dairy = "dairy"
        case frozen = "frozen"
        case other = "other"
    }
}

And this is the data representation I'm aiming to get:

"title": String,
"date": String,
"description": String,
"items": [
     "header1": [{
          "name": String,
          "quantity": String
          },
          {
          "name": String,
          "quantity": String
          }
     ],
     "header2": [{
          "name": String,
          "quantity": String
          },
          {
          "name": String,
          "quantity": String
          }
     ]
]

Any help would be great! Thanks in advance!

jkva17
  • 11
  • 1
  • According to this [post](https://stackoverflow.com/questions/46593953/nested-arrays-are-not-supported%22), directly, nested arrays are not supported. You can have an array that contains an object that contains arrays, or a different data structure altogether. I would suggest you bring this issue up to the [Firebase Support page](https://firebase.google.com/support/troubleshooter/contact) as they would be better suited in answering your questions and concerns pertaining to this error. – Jan L Jul 11 '20 at 00:23
  • Ok, that makes sense. I'll check that out. Thanks! – jkva17 Jul 12 '20 at 03:40

0 Answers0