Fixed default value of bool in struct for Swift (#7072)

This commit is contained in:
nicked
2022-02-02 21:39:19 +01:00
committed by GitHub
parent 619b784374
commit a2b238960f
5 changed files with 149 additions and 29 deletions

View File

@@ -220,8 +220,10 @@ class SwiftGenerator : public BaseGenerator {
IsEnum(field.value.type) ? "{{BASEVALUE}}" : "{{VALUETYPE}}";
code_ += "private var _{{VALUENAME}}: " + valueType;
auto accessing_value = IsEnum(field.value.type) ? ".value" : "";
auto base_value =
IsStruct(field.value.type) ? (type + "()") : field.value.constant;
auto is_bool = IsBool(field.value.type.base_type);
auto base_value = IsStruct(field.value.type) ? (type + "()")
: is_bool ? ("0" == field.value.constant ? "false" : "true")
: field.value.constant;
main_constructor.push_back("_" + name + " = " + name + accessing_value);
base_constructor.push_back("_" + name + " = " + base_value);