struct ProspectAdditionalField: Mappable {
// MARK: Props
var key: String?
var type: AdditionalFieldType?
var name: String?
var hint: String?
var required: Bool?
var validationRegex: String?
var validationError: String?
var validationCustom: String?
var value: String?
var minValue: String?
var maxValue: String?
var isForQuote: Bool?
var prospectField: String?
var options: [Option]?
// MARK: Constructors
init() {
}
init(key: String) {
self.key = key
}
init(key: String, required: Bool) {
self.key = key
self.required = required
}
init(type: AdditionalFieldType?, value: String?) {
self.type = type
self.value = value
self.required = false
self.isForQuote = false
}
init?(map: Map) {
}
// MARK: Mapping
mutating func mapping(map: Map) {
key <- map["key"]
type <- map["type"]
name <- map["name"]
hint <- map["hint"]
required <- map["required"]
validationRegex <- map["validationRegex"]
validationError <- map["validationError"]
validationCustom <- map["validationCustom"]
value <- map["value"]
minValue <- map["minValue"]
maxValue <- map["maxValue"]
isForQuote <- map["isForQuote"]
prospectField <- map["prospectField"]
options <- map["options"]
}
func getValueFromOptions(key: String) -> String?{
guard let options = options else {
return nil
}
for option in options {
if option.value == key {
return option.text
}
}
return nil
}
}
struct Option: Mappable {
var text: String?
var value: String?
// MARK: Constructors
init() {
}
init?(map: Map) {
}
// MARK: Mapping
mutating func mapping(map: Map) {
text <- map["text"]
value <- map["value"]
}
}
What you did:
decode the json where this json is part of a very long json file that is decoded correct all values but the array does not keep the original order of the json.
let repo = Mapper<Repo>().map(myJSONDictionary)
use the values in options to show a alert with multiples actions like this
for option in field.options! {
let action = UIAlertAction(title: option.text, style: .default) { (action) in
row.value = option.text
row.valueKey = option.value
}
alertController.addAction(action)
}
Your JSON dictionary:
Your model:
What you did:
decode the json where this json is part of a very long json file that is decoded correct all values but the array does not keep the original order of the json.
use the values in options to show a alert with multiples actions like this
What you expected:
show actions in the order of the json.
What you got: