jeudi 17 décembre 2015

GRDB Sync with nested array

I am using GRDB to sync my JSON payload to SQLite however I am encountering an error whenever I have an array of other items within the main payload.

fatal error: unexpectedly found nil while unwrapping an Optional value

My JSON is:

{ "newsData": [
  {
    "newsID" : 6,
    "content" : "Test",
    "author" : "Test Author",
    "published" : 1,
    "title" : "Test news",
    "dateAdded" : "2015-12-18 11:33:15",
    "imagePath" : null,
    "newsCategoryData" : [

    ],
    "shortDescription" : "Test",
    "newsTagData" : [

    ],
    "lastModified" : null
  },

as you can see I have newsCategoryData and newsTagData as arrays. The sync is:

 do {
   let jsonString =
      "{ \"newsData\": " +
        "\(responseJSON["newsData"]) " +
      "}"
    try dbQueue.inTransaction { db in
      try self.synchronizeNewsWithJSON(jsonString, inDatabase: db)
      return .Commit
    }
}

The issue is newsCategoryData and newsTagData because if I remove those from the payload everything syncs correctly. Is it possible to ignore these 2 items when performing a sync as I will sync these 2 at a later stage.

Thanks

Aucun commentaire:

Enregistrer un commentaire