-1

App Crashes when deserializing a struct after parsing the JSON from the api, After updating xCode to Version 9.3, a crash started to appear ,i cant figure out or diagnose what the problem is or why it's happening, the crash or the error happens here as it shows in the image bellow;

HANDYJSON/NominalTypeDescriptor/numberOfFields

import UIKit
import HandyJSON
import EventKit

class PlayersViewController:UIViewController{
    var personsArray=[PersonData]()

            func getAllPlayers(){
                let params = ["id":"5"]
                Communicator.performAsyncRequest(httpMethod: .post, apiName:Helper.sharedInstance().getActivityWithoutSyncID, parameters: params , showHUD: false) { (isSuccess, error, response, message) in

                    if isSuccess && response != nil {

                        let jsonData = try! JSONSerialization.data(withJSONObject: response as Any, options: JSONSerialization.WritingOptions.prettyPrinted)
                        let jsonString = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue)! as String

                        print(jsonString)

                        if let Persons = PersonStruct.deserialize(from: jsonString) {
                            if Persons.Status == "S200"{
                                for person in PersonsStruct.Data {
                                    self.personsArray.append(person)
                                }
                            }
                        }
                      }
                    }
         }
        struct PersonStruct: HandyJSON {
            var Status:String?
            var Data=[PersonData]()
            var Error = [String]()
            var Extra = SyncActivityStructExtra()
        }
        struct PersonData:HandyJSON{
            var id:String?
            var name:String?
            var phoneNumber:String?    
        }

thanks in advance!

Sanad Barjawi
  • 539
  • 4
  • 15
  • 1
    Please show your code in text, with all relevant parts. – OOPer Apr 01 '18 at 09:20
  • I couldn't help to notice the following in the README for the HandyJSON project, "HandyJSON is totally depend on the memory layout rules infered from Swift runtime code. We are watching it and will follow every bit if it changes." – Joakim Danielson Apr 01 '18 at 10:15

1 Answers1

0

The issue has been reported in the HandyJSON project and there seems to be a solution. So you have three options

  1. Downgrade to Swift 4.0 and wait for next release
  2. Download code and implement the fix yourself
  3. Find other solution for JSON, like Swift built in support using Codable.
Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52