¿Cómo convertir JSON a un diccionario en iOS rápido?

Hola, estoy haciendo una aplicación que funciona con una API. Tengo un código de trabajo que recibe datos de la API. Pero pensé que sería mejor hacer mi código un poco más limpio. Quiero configurar los datos de la API en un diccionario, pero no puedo hacer que funcione. Cualquier ayuda sería apreciada, gracias!

Aquí está el resultado de la API:

Quiero configurar el AutorId y BranchId, etc., etc. en un diccionario. Y este es el código que tengo ahora. Esta es la clase de proyecto:

class Project: NSObject {
var AuthorId: String?
var BranchId: String?
var CompanyId: String?
var ContactId: String?
var Date: String?
var Deadline: String?
var Description: String?
var Id: String?
var State: String?
init(dictionary: [String: Any]) {
    self.AuthorId = dictionary["AuthorId"] as? String
    self.BranchId = dictionary["BranchId"] as? String
    self.CompanyId = dictionary["CompanyId"] as? String
    self.ContactId = dictionary["ContactId"] as? String
    self.Date = dictionary["Date"] as? String
    self.Deadline = dictionary["Deadline"] as? String
    self.Description = dictionary["Description"] as? String
    self.Id = dictionary["Id"] as? String
    self.State = dictionary["State"] as? String

}

}

y aquí estoy tratando de configurarlo en un diccionario:

func apiRequest() {
    apiRequestHeader()
    var running = false
    let urlProjects = NSURL(string: "https://start.jamespro.nl/v4/api/json/projects/?limit=10")
    let task = session?.dataTask(with: urlProjects! as URL) {
        ( data, response, error) in
        if let taskHeader = response as? HTTPURLResponse {
            print(taskHeader.statusCode)
        }
        if error != nil {
            print("There is an error!!!")
            print(error)
        } else {
            if let content = data {
                do {
                    let dictionary = try JSONSerialization.jsonObject(with: content) as! [String:Any]
                    print(dictionary)

                    if let items = dictionary["items"] as? [[String:Any]] {
                        let project = Project(dictionary: items)
                        print(project)
                        self.projects.append(project)

                        DispatchQueue.main.async(execute: {
                            self.tableView.reloadData()
                        })

                    }
                }
                catch {
                    print("Error: Could not get any data")
                }
            }
        }
        running = false
    }


    running = true
    task?.resume()

    while running {
        print("waiting...")
        sleep(1)
    }

}

Respuestas a la pregunta(0)

Su respuesta a la pregunta