I am trying to parse long response data :
below is the code structure
struct VizLog_UserProfile: Codable {
let data: UserProfileData
let app: App
}
struct UserProfileData: Codable {
let roles: [String]
let users: UserDetails
let member: ProfileMember
enum CodingKeys: String, CodingKey {
case roles
case users
case member
}
}
struct UserDetails: Codable {
let user_id: String
let auth_id: String
let unit_id: String
let company_id: String
let visitor_id: String
let session_token: String
let gender: String
let visitor_type: String
let email: String
let first_name: String
let last_name: String
let mobile: String
let avatar: String
var complex: Complex? = nil
enum CodingKeys: String, CodingKey {
case user_id
case auth_id
case unit_id
case company_id
case visitor_id
case session_token
case gender
case visitor_type
case email
case first_name
case last_name
case mobile
case avatar
case complex = "complex"
}
enum Complex_CodingKeys: String, CodingKey {
case company_id
case unit_id
case complex_name
case setup_steps
case complex_type
case access_type
case pass_type
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
user_id = getValUserDetails(key: .user_id, decoder: decoder, container: container)
auth_id = getValUserDetails(key: .auth_id, decoder: decoder, container: container)
unit_id = getValUserDetails(key: .unit_id, decoder: decoder, container: container)
company_id = getValUserDetails(key: .company_id, decoder: decoder, container: container)
visitor_id = getValUserDetails(key: .visitor_id, decoder: decoder, container: container)
session_token = getValUserDetails(key: .session_token, decoder: decoder, container: container)
gender = getValUserDetails(key: .gender, decoder: decoder, container: container)
visitor_type = getValUserDetails(key: .visitor_type, decoder: decoder, container: container)
email = getValUserDetails(key: .email, decoder: decoder, container: container)
first_name = getValUserDetails(key: .first_name, decoder: decoder, container: container)
last_name = getValUserDetails(key: .last_name, decoder: decoder, container: container)
mobile = getValUserDetails(key: .mobile, decoder: decoder, container: container)
avatar = getValUserDetails(key: .avatar, decoder: decoder, container: container)
var tmpComplexUnkeyedContainer = try container.nestedUnkeyedContainer(forKey: .complex)
var tmpComplex : Complex? = nil
let tmpComplexContainer = try tmpComplexUnkeyedContainer.nestedContainer(keyedBy: Complex.CodingKeys.self)
tmpComplex?.company_id = getValComplex(key: .company_id, container: tmpComplexContainer)
tmpComplex?.unit_id = getValComplex(key: .unit_id, container: tmpComplexContainer)
tmpComplex?.complex_name = getValComplex(key: .complex_name, container: tmpComplexContainer)
tmpComplex?.setup_steps = getValComplex(key: .setup_steps, container: tmpComplexContainer)
tmpComplex?.complex_type = getValComplex(key: .complex_type, container: tmpComplexContainer)
tmpComplex?.access_type = getValComplex(key: .access_type, container: tmpComplexContainer)
tmpComplex?.pass_type = getValComplex(key: .pass_type, container: tmpComplexContainer)
complex = tmpComplex
}
}
struct ProfileMember: Codable {
public var units: [String: ProfileUnits]
let parking: [String]
}
struct ProfileUnits: Codable {
let unit_type: String
let building_name: String
let unit_number: String
let building_unit_id: String
enum CodingKeys: String, CodingKey {
case unit_type
case building_name
case unit_number
case building_unit_id
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
unit_type = getValProfileMember(key: .unit_type, decoder: decoder, container: container)
building_name = getValProfileMember(key: .building_name, decoder: decoder, container: container)
unit_number = getValProfileMember(key: .unit_number, decoder: decoder, container: container)
building_unit_id = getValProfileMember(key: .building_unit_id, decoder: decoder, container: container)
}
}
struct Subscribed_Applications: Codable {
let app_id: String
let app_name: String
let app_version: String
let logo: String
let end_point: String
let logo_small: String
let logo_medium: String
let logo_large: String
let logo_xsmall: String
}
struct Complex: Codable {
var company_id: String
var unit_id: String
var complex_name: String
var setup_steps: String
var complex_type: String
var access_type: String
var pass_type: String
//let complex_events: [String]
enum CodingKeys: String, CodingKey {
case company_id
case unit_id
case complex_name
case setup_steps
case complex_type
case access_type
case pass_type
//case complex_events
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
company_id = getValComplex(key: .company_id, container: container)
unit_id = getValComplex(key: .unit_id, container: container)
complex_name = getValComplex(key: .complex_name, container: container)
setup_steps = getValComplex(key: .setup_steps, container: container)
complex_type = getValComplex(key: .complex_type, container: container)
access_type = getValComplex(key: .access_type, container: container)
pass_type = getValComplex(key: .pass_type, container: container)
//complex_events = getValComplex(key: .complex_events, container: container)
}
}
This is the actual Response which I am trying to parse :
{
"app": {
"version": "v1",
"name": "CHSONE Vizlog",
"time": "2019-02-07 05:31:08"
},
"status_code": 200,
"data": {
"metadata": {
"total": 64899,
"per_page": 10,
"current_page": 1,
"last_page": 6490,
"from": 1,
"to": 10
},
"results": [
{
"log_id": 64899,
"fk_visitor_id": 65103,
"fk_building_unit_id": 97,
"company_id": 7,
"pass_serial_no": null,
"card_no": null,
"number_of_people": 1,
"purpose_of_visit": "Meeting",
"in_gate": "Lobby",
"in_time": "2019-02-06 12:24:31",
"out_time": null,
"out_gate": null,
"in_vehicle_no": null,
"out_vehicle_no": null,
"in_vehicle_color": null,
"out_vehicle_color": null,
"is_handed_over": 0,
"access_type": "card",
"created_at": "2019-02-06 12:24:31",
"updated_at": "2019-02-06 12:24:31",
"created_by": 151,
"updated_by": null,
"visitors": {
"visitor_id": 65103,
"visitor_company_name": null,
"designation": null,
"industry": null,
"used_promotional_channel": null,
"interested_in": null,
"platform": "android",
"iso_code": "IN",
"dial_code": "91",
"company_id": 7,
"first_name": "praduman",
"last_name": null,
"gender": "M",
"mobile": "9080706050",
"email": null,
"image_path": null,
"visitor_type": "guest",
"coming_from": "vashi",
"image_large": null,
"image_medium": null,
"image_small": null
},
"unit": {
"building_unit_id": 97,
"fk_building_id": 1,
"unit_number": "1905",
"floor_no": "19",
"building": {
"building_id": 1,
"building_name": "CyberOne"
}
}
},
{
"log_id": 64898,
"fk_visitor_id": 65054,
"fk_building_unit_id": 97,
"company_id": 7,
"pass_serial_no": null,
"card_no": null,
"number_of_people": 1,
"purpose_of_visit": "Meeting",
"in_gate": "Lobby",
"in_time": "2019-02-06 12:19:06",
"out_time": null,
"out_gate": null,
"in_vehicle_no": null,
"out_vehicle_no": null,
"in_vehicle_color": null,
"out_vehicle_color": null,
"is_handed_over": 0,
"access_type": "card",
"created_at": "2019-02-06 12:19:06",
"updated_at": "2019-02-06 12:19:06",
"created_by": 151,
"updated_by": null,
"visitors": {
"visitor_id": 65054,
"visitor_company_name": null,
"designation": null,
"industry": null,
"used_promotional_channel": null,
"interested_in": null,
"platform": null,
"iso_code": "IN",
"dial_code": "91",
"company_id": 7,
"first_name": "Amit",
"last_name": "Dhawale",
"gender": "M",
"mobile": "8055954796",
"email": null,
"image_path": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054.jpg",
"visitor_type": "guest",
"coming_from": "sanpada",
"image_large": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054_large.jpg",
"image_medium": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054_medium.jpg",
"image_small": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054_small.jpg"
},
"unit": {
"building_unit_id": 97,
"fk_building_id": 1,
"unit_number": "1905",
"floor_no": "19",
"building": {
"building_id": 1,
"building_name": "CyberOne"
}
}
},
{
"log_id": 64897,
"fk_visitor_id": 57222,
"fk_building_unit_id": 24,
"company_id": 7,
"pass_serial_no": null,
"card_no": null,
"number_of_people": 1,
"purpose_of_visit": "Meeting",
"in_gate": "Lobby",
"in_time": "2019-02-06 12:08:08",
"out_time": null,
"out_gate": null,
"in_vehicle_no": null,
"out_vehicle_no": null,
"in_vehicle_color": null,
"out_vehicle_color": null,
"is_handed_over": 0,
"access_type": "card",
"created_at": "2019-02-06 12:08:08",
"updated_at": "2019-02-06 12:08:08",
"created_by": 151,
"updated_by": null,
"visitors": {
"visitor_id": 57222,
"visitor_company_name": null,
"designation": null,
"industry": null,
"used_promotional_channel": null,
"interested_in": null,
"platform": null,
"iso_code": "IN",
"dial_code": "91",
"company_id": 7,
"first_name": "Praduman",
"last_name": "Patil",
"gender": "M",
"mobile": "9420256819",
"email": null,
"image_path": null,
"visitor_type": "guest",
"coming_from": "Future Scape interview",
"image_large": null,
"image_medium": null,
"image_small": null
},
"unit": {
"building_unit_id": 24,
"fk_building_id": 1,
"unit_number": "1001",
"floor_no": "10",
"building": {
"building_id": 1,
"building_name": "CyberOne"
}
}
},
{
"log_id": 64896,
"fk_visitor_id": 65054,
"fk_building_unit_id": 96,
"company_id": 7,
"pass_serial_no": null,
"card_no": null,
"number_of_people": 1,
"purpose_of_visit": "Meeting",
"in_gate": "Lobby",
"in_time": "2019-01-31 12:34:18",
"out_time": "2019-01-31 12:40:30",
"out_gate": "Lobby",
"in_vehicle_no": null,
"out_vehicle_no": null,
"in_vehicle_color": null,
"out_vehicle_color": null,
"is_handed_over": 1,
"access_type": "card",
"created_at": "2019-01-31 12:34:18",
"updated_at": "2019-01-31 12:40:30",
"created_by": 152,
"updated_by": 151,
"visitors": {
"visitor_id": 65054,
"visitor_company_name": null,
"designation": null,
"industry": null,
"used_promotional_channel": null,
"interested_in": null,
"platform": null,
"iso_code": "IN",
"dial_code": "91",
"company_id": 7,
"first_name": "Amit",
"last_name": "Dhawale",
"gender": "M",
"mobile": "8055954796",
"email": null,
"image_path": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054.jpg",
"visitor_type": "guest",
"coming_from": "sanpada",
"image_large": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054_large.jpg",
"image_medium": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054_medium.jpg",
"image_small": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054_small.jpg"
},
"unit": {
"building_unit_id": 96,
"fk_building_id": 1,
"unit_number": "1904",
"floor_no": "19",
"building": {
"building_id": 1,
"building_name": "CyberOne"
}
}
},
{
"log_id": 64895,
"fk_visitor_id": 65054,
"fk_building_unit_id": 96,
"company_id": 7,
"pass_serial_no": null,
"card_no": null,
"number_of_people": 1,
"purpose_of_visit": "Meeting",
"in_gate": "Lobby",
"in_time": "2019-01-31 11:35:09",
"out_time": null,
"out_gate": null,
"in_vehicle_no": null,
"out_vehicle_no": null,
"in_vehicle_color": null,
"out_vehicle_color": null,
"is_handed_over": 0,
"access_type": "card",
"created_at": "2019-01-31 11:35:09",
"updated_at": "2019-01-31 11:35:09",
"created_by": 151,
"updated_by": null,
"visitors": {
"visitor_id": 65054,
"visitor_company_name": null,
"designation": null,
"industry": null,
"used_promotional_channel": null,
"interested_in": null,
"platform": null,
"iso_code": "IN",
"dial_code": "91",
"company_id": 7,
"first_name": "Amit",
"last_name": "Dhawale",
"gender": "M",
"mobile": "8055954796",
"email": null,
"image_path": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054.jpg",
"visitor_type": "guest",
"coming_from": "sanpada",
"image_large": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054_large.jpg",
"image_medium": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054_medium.jpg",
"image_small": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_65054_small.jpg"
},
"unit": {
"building_unit_id": 96,
"fk_building_id": 1,
"unit_number": "1904",
"floor_no": "19",
"building": {
"building_id": 1,
"building_name": "CyberOne"
}
}
},
{
"log_id": 64894,
"fk_visitor_id": 65102,
"fk_building_unit_id": 97,
"company_id": 7,
"pass_serial_no": null,
"card_no": null,
"number_of_people": 1,
"purpose_of_visit": "Meeting",
"in_gate": "Lobby",
"in_time": "2019-01-28 14:01:24",
"out_time": null,
"out_gate": null,
"in_vehicle_no": null,
"out_vehicle_no": null,
"in_vehicle_color": null,
"out_vehicle_color": null,
"is_handed_over": 0,
"access_type": "card",
"created_at": "2019-01-28 14:01:24",
"updated_at": "2019-01-28 14:01:24",
"created_by": 151,
"updated_by": null,
"visitors": {
"visitor_id": 65102,
"visitor_company_name": null,
"designation": null,
"industry": null,
"used_promotional_channel": null,
"interested_in": null,
"platform": "android",
"iso_code": "IN",
"dial_code": "91",
"company_id": 7,
"first_name": "hzhd",
"last_name": null,
"gender": "M",
"mobile": "8055678855",
"email": null,
"image_path": null,
"visitor_type": "guest",
"coming_from": "vashi",
"image_large": null,
"image_medium": null,
"image_small": null
},
"unit": {
"building_unit_id": 97,
"fk_building_id": 1,
"unit_number": "1905",
"floor_no": "19",
"building": {
"building_id": 1,
"building_name": "CyberOne"
}
}
},
{
"log_id": 64893,
"fk_visitor_id": 65101,
"fk_building_unit_id": 96,
"company_id": 7,
"pass_serial_no": null,
"card_no": null,
"number_of_people": 1,
"purpose_of_visit": "Meeting",
"in_gate": "Lobby",
"in_time": "2019-01-28 14:00:40",
"out_time": null,
"out_gate": null,
"in_vehicle_no": null,
"out_vehicle_no": null,
"in_vehicle_color": null,
"out_vehicle_color": null,
"is_handed_over": 0,
"access_type": "card",
"created_at": "2019-01-28 14:00:40",
"updated_at": "2019-01-28 14:00:40",
"created_by": 151,
"updated_by": null,
"visitors": {
"visitor_id": 65101,
"visitor_company_name": null,
"designation": null,
"industry": null,
"used_promotional_channel": null,
"interested_in": null,
"platform": "android",
"iso_code": "IN",
"dial_code": "91",
"company_id": 7,
"first_name": "test",
"last_name": "sync",
"gender": "M",
"mobile": "8056799285",
"email": null,
"image_path": null,
"visitor_type": "guest",
"coming_from": "vashi",
"image_large": null,
"image_medium": null,
"image_small": null
},
"unit": {
"building_unit_id": 96,
"fk_building_id": 1,
"unit_number": "1904",
"floor_no": "19",
"building": {
"building_id": 1,
"building_name": "CyberOne"
}
}
},
{
"log_id": 64892,
"fk_visitor_id": 47,
"fk_building_unit_id": 97,
"company_id": 7,
"pass_serial_no": null,
"card_no": null,
"number_of_people": 1,
"purpose_of_visit": "Meeting",
"in_gate": "Lobby",
"in_time": "2019-01-28 13:47:42",
"out_time": null,
"out_gate": null,
"in_vehicle_no": null,
"out_vehicle_no": null,
"in_vehicle_color": null,
"out_vehicle_color": null,
"is_handed_over": 0,
"access_type": "card",
"created_at": "2019-01-28 13:47:42",
"updated_at": "2019-01-28 13:47:42",
"created_by": 151,
"updated_by": null,
"visitors": {
"visitor_id": 47,
"visitor_company_name": null,
"designation": null,
"industry": null,
"used_promotional_channel": null,
"interested_in": null,
"platform": null,
"iso_code": "IN",
"dial_code": "91",
"company_id": 7,
"first_name": "KOTESHWAR",
"last_name": "DEVELOPERS",
"gender": "",
"mobile": "9819328361",
"email": "krishnaenterprises400#gmail.com",
"image_path": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_47.jpg",
"visitor_type": "member",
"coming_from": null,
"image_large": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_47_large.jpg",
"image_medium": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_47_medium.jpg",
"image_small": "http://test.prosimvizlog.s3-ap-southeast-1.amazonaws.com/7/visitor/visitor_47_small.jpg"
},
"unit": {
"building_unit_id": 97,
"fk_building_id": 1,
"unit_number": "1905",
"floor_no": "19",
"building": {
"building_id": 1,
"building_name": "CyberOne"
}
}
},
{
"log_id": 64891,
"fk_visitor_id": 65100,
"fk_building_unit_id": 96,
"company_id": 7,
"pass_serial_no": null,
"card_no": "V013",
"number_of_people": 1,
"purpose_of_visit": "Meeting",
"in_gate": "Lobby",
"in_time": "2019-01-22 05:00:43",
"out_time": null,
"out_gate": null,
"in_vehicle_no": null,
"out_vehicle_no": null,
"in_vehicle_color": null,
"out_vehicle_color": null,
"is_handed_over": 0,
"access_type": "card",
"created_at": "2019-01-22 05:00:43",
"updated_at": "2019-01-22 05:00:45",
"created_by": 151,
"updated_by": null,
"visitors": {
"visitor_id": 65100,
"visitor_company_name": null,
"designation": null,
"industry": null,
"used_promotional_channel": null,
"interested_in": null,
"platform": "android",
"iso_code": "IN",
"dial_code": "91",
"company_id": 7,
"first_name": "test",
"last_name": null,
"gender": "M",
"mobile": "8097679764",
"email": null,
"image_path": null,
"visitor_type": "guest",
"coming_from": "vashi",
"image_large": null,
"image_medium": null,
"image_small": null
},
"unit": {
"building_unit_id": 96,
"fk_building_id": 1,
"unit_number": "1904",
"floor_no": "19",
"building": {
"building_id": 1,
"building_name": "CyberOne"
}
}
},
{
"log_id": 64890,
"fk_visitor_id": 65099,
"fk_building_unit_id": 96,
"company_id": 7,
"pass_serial_no": null,
"card_no": null,
"number_of_people": 1,
"purpose_of_visit": "nnxnx",
"in_gate": "Lobby",
"in_time": "2019-01-21 13:20:07",
"out_time": null,
"out_gate": null,
"in_vehicle_no": null,
"out_vehicle_no": null,
"in_vehicle_color": null,
"out_vehicle_color": null,
"is_handed_over": 0,
"access_type": "card",
"created_at": "2019-01-21 13:20:07",
"updated_at": "2019-01-21 13:20:07",
"created_by": 151,
"updated_by": null,
"visitors": {
"visitor_id": 65099,
"visitor_company_name": null,
"designation": null,
"industry": null,
"used_promotional_channel": null,
"interested_in": null,
"platform": "android",
"iso_code": "IN",
"dial_code": "91",
"company_id": 7,
"first_name": "jznznz",
"last_name": null,
"gender": "M",
"mobile": "9767967797",
"email": null,
"image_path": null,
"visitor_type": "guest",
"coming_from": "hzbzs",
"image_large": null,
"image_medium": null,
"image_small": null
},
"unit": {
"building_unit_id": 96,
"fk_building_id": 1,
"unit_number": "1904",
"floor_no": "19",
"building": {
"building_id": 1,
"building_name": "CyberOne"
}
}
}
]
}
}
It returns with the error :
Error info: typeMismatch(Swift.Array, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "data", intValue: nil), CodingKeys(stringValue: "users", intValue: nil)], debugDescription: "Expected to decode Array but found a dictionary instead.", underlyingError: nil))
Below is the exact line where it causes the error :
var tmpComplexUnkeyedContainer = try container.nestedUnkeyedContainer(forKey: .complex)
Can someone suggest me reason.
Thank you.
Codable structures created by you are not parsable from your given response.
Please try below structure.
// To parse the JSON, add this file to your project and do:
// var respData = try? newJSONDecoder().decode(RespData.self, from: jsonData)
import Foundation
class RespData: Codable {
var app: App?
var statusCode: Int?
var data: DataClass?
enum CodingKeys: String, CodingKey {
case app = "app"
case statusCode = "status_code"
case data = "data"
}
init(app: App?, statusCode: Int?, data: DataClass?) {
self.app = app
self.statusCode = statusCode
self.data = data
}
}
class App: Codable {
var version: String?
var name: String?
var time: String?
enum CodingKeys: String, CodingKey {
case version = "version"
case name = "name"
case time = "time"
}
init(version: String?, name: String?, time: String?) {
self.version = version
self.name = name
self.time = time
}
}
class DataClass: Codable {
var metadata: Metadata?
var results: [Result]?
enum CodingKeys: String, CodingKey {
case metadata = "metadata"
case results = "results"
}
init(metadata: Metadata?, results: [Result]?) {
self.metadata = metadata
self.results = results
}
}
class Metadata: Codable {
var total: Int?
var perPage: Int?
var currentPage: Int?
var lastPage: Int?
var from: Int?
var to: Int?
enum CodingKeys: String, CodingKey {
case total = "total"
case perPage = "per_page"
case currentPage = "current_page"
case lastPage = "last_page"
case from = "from"
case to = "to"
}
init(total: Int?, perPage: Int?, currentPage: Int?, lastPage: Int?, from: Int?, to: Int?) {
self.total = total
self.perPage = perPage
self.currentPage = currentPage
self.lastPage = lastPage
self.from = from
self.to = to
}
}
class Result: Codable {
var logID: Int?
var fkVisitorID: Int?
var fkBuildingUnitID: Int?
var companyID: Int?
var passSerialNo: JSONNull?
var cardNo: String?
var numberOfPeople: Int?
var purposeOfVisit: PurposeOfVisit?
var inGate: Gate?
var inTime: String?
var outTime: String?
var outGate: Gate?
var inVehicleNo: JSONNull?
var outVehicleNo: JSONNull?
var inVehicleColor: JSONNull?
var outVehicleColor: JSONNull?
var isHandedOver: Int?
var accessType: AccessType?
var createdAt: String?
var updatedAt: String?
var createdBy: Int?
var updatedBy: Int?
var visitors: Visitors?
var unit: Unit?
enum CodingKeys: String, CodingKey {
case logID = "log_id"
case fkVisitorID = "fk_visitor_id"
case fkBuildingUnitID = "fk_building_unit_id"
case companyID = "company_id"
case passSerialNo = "pass_serial_no"
case cardNo = "card_no"
case numberOfPeople = "number_of_people"
case purposeOfVisit = "purpose_of_visit"
case inGate = "in_gate"
case inTime = "in_time"
case outTime = "out_time"
case outGate = "out_gate"
case inVehicleNo = "in_vehicle_no"
case outVehicleNo = "out_vehicle_no"
case inVehicleColor = "in_vehicle_color"
case outVehicleColor = "out_vehicle_color"
case isHandedOver = "is_handed_over"
case accessType = "access_type"
case createdAt = "created_at"
case updatedAt = "updated_at"
case createdBy = "created_by"
case updatedBy = "updated_by"
case visitors = "visitors"
case unit = "unit"
}
init(logID: Int?, fkVisitorID: Int?, fkBuildingUnitID: Int?, companyID: Int?, passSerialNo: JSONNull?, cardNo: String?, numberOfPeople: Int?, purposeOfVisit: PurposeOfVisit?, inGate: Gate?, inTime: String?, outTime: String?, outGate: Gate?, inVehicleNo: JSONNull?, outVehicleNo: JSONNull?, inVehicleColor: JSONNull?, outVehicleColor: JSONNull?, isHandedOver: Int?, accessType: AccessType?, createdAt: String?, updatedAt: String?, createdBy: Int?, updatedBy: Int?, visitors: Visitors?, unit: Unit?) {
self.logID = logID
self.fkVisitorID = fkVisitorID
self.fkBuildingUnitID = fkBuildingUnitID
self.companyID = companyID
self.passSerialNo = passSerialNo
self.cardNo = cardNo
self.numberOfPeople = numberOfPeople
self.purposeOfVisit = purposeOfVisit
self.inGate = inGate
self.inTime = inTime
self.outTime = outTime
self.outGate = outGate
self.inVehicleNo = inVehicleNo
self.outVehicleNo = outVehicleNo
self.inVehicleColor = inVehicleColor
self.outVehicleColor = outVehicleColor
self.isHandedOver = isHandedOver
self.accessType = accessType
self.createdAt = createdAt
self.updatedAt = updatedAt
self.createdBy = createdBy
self.updatedBy = updatedBy
self.visitors = visitors
self.unit = unit
}
}
enum AccessType: String, Codable {
case card = "card"
}
enum Gate: String, Codable {
case lobby = "Lobby"
}
enum PurposeOfVisit: String, Codable {
case meeting = "Meeting"
case nnxnx = "nnxnx"
}
class Unit: Codable {
var buildingUnitID: Int?
var fkBuildingID: Int?
var unitNumber: String?
var floorNo: String?
var building: Building?
enum CodingKeys: String, CodingKey {
case buildingUnitID = "building_unit_id"
case fkBuildingID = "fk_building_id"
case unitNumber = "unit_number"
case floorNo = "floor_no"
case building = "building"
}
init(buildingUnitID: Int?, fkBuildingID: Int?, unitNumber: String?, floorNo: String?, building: Building?) {
self.buildingUnitID = buildingUnitID
self.fkBuildingID = fkBuildingID
self.unitNumber = unitNumber
self.floorNo = floorNo
self.building = building
}
}
class Building: Codable {
var buildingID: Int?
var buildingName: BuildingName?
enum CodingKeys: String, CodingKey {
case buildingID = "building_id"
case buildingName = "building_name"
}
init(buildingID: Int?, buildingName: BuildingName?) {
self.buildingID = buildingID
self.buildingName = buildingName
}
}
enum BuildingName: String, Codable {
case cyberOne = "CyberOne"
}
class Visitors: Codable {
var visitorID: Int?
var visitorCompanyName: JSONNull?
var designation: JSONNull?
var industry: JSONNull?
var usedPromotionalChannel: JSONNull?
var interestedIn: JSONNull?
var platform: String?
var isoCode: ISOCode?
var dialCode: String?
var companyID: Int?
var firstName: String?
var lastName: String?
var gender: Gender?
var mobile: String?
var email: String?
var imagePath: String?
var visitorType: VisitorType?
var comingFrom: String?
var imageLarge: String?
var imageMedium: String?
var imageSmall: String?
enum CodingKeys: String, CodingKey {
case visitorID = "visitor_id"
case visitorCompanyName = "visitor_company_name"
case designation = "designation"
case industry = "industry"
case usedPromotionalChannel = "used_promotional_channel"
case interestedIn = "interested_in"
case platform = "platform"
case isoCode = "iso_code"
case dialCode = "dial_code"
case companyID = "company_id"
case firstName = "first_name"
case lastName = "last_name"
case gender = "gender"
case mobile = "mobile"
case email = "email"
case imagePath = "image_path"
case visitorType = "visitor_type"
case comingFrom = "coming_from"
case imageLarge = "image_large"
case imageMedium = "image_medium"
case imageSmall = "image_small"
}
init(visitorID: Int?, visitorCompanyName: JSONNull?, designation: JSONNull?, industry: JSONNull?, usedPromotionalChannel: JSONNull?, interestedIn: JSONNull?, platform: String?, isoCode: ISOCode?, dialCode: String?, companyID: Int?, firstName: String?, lastName: String?, gender: Gender?, mobile: String?, email: String?, imagePath: String?, visitorType: VisitorType?, comingFrom: String?, imageLarge: String?, imageMedium: String?, imageSmall: String?) {
self.visitorID = visitorID
self.visitorCompanyName = visitorCompanyName
self.designation = designation
self.industry = industry
self.usedPromotionalChannel = usedPromotionalChannel
self.interestedIn = interestedIn
self.platform = platform
self.isoCode = isoCode
self.dialCode = dialCode
self.companyID = companyID
self.firstName = firstName
self.lastName = lastName
self.gender = gender
self.mobile = mobile
self.email = email
self.imagePath = imagePath
self.visitorType = visitorType
self.comingFrom = comingFrom
self.imageLarge = imageLarge
self.imageMedium = imageMedium
self.imageSmall = imageSmall
}
}
enum Gender: String, Codable {
case empty = ""
case m = "M"
}
enum ISOCode: String, Codable {
case isoCodeIN = "IN"
}
enum VisitorType: String, Codable {
case guest = "guest"
case member = "member"
}
// MARK: Encode/decode helpers
class JSONNull: Codable, Hashable {
public static func == (lhs: JSONNull, rhs: JSONNull) -> Bool {
return true
}
public var hashValue: Int {
return 0
}
public init() {}
public required init(from decoder: Decoder) throws {
var container = try decoder.singleValueContainer()
if !container.decodeNil() {
throw DecodingError.typeMismatch(JSONNull.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for JSONNull"))
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encodeNil()
}
}