Skip to content

Commit e042a23

Browse files
committed
fix: index checks
1 parent e9fb017 commit e042a23

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

templates/cli/lib/type-generation/languages/swift.js.twig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
107107

108108
public func toMap() -> [String: Any] {
109109
return [
110-
<% for (const attribute of collection.attributes) { -%>
110+
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
111111
<% if (attribute.type === 'relationship') { -%>
112112
"<%- attribute.key %>": <%- toCamelCase(attribute.key) %> as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
113113
<% } else if (attribute.array && attribute.type !== 'string' && attribute.type !== 'integer' && attribute.type !== 'float' && attribute.type !== 'boolean') { -%>
@@ -130,29 +130,29 @@ public class <%- toPascalCase(collection.name) %>: Codable {
130130
<% } -%>
131131
<% } else if (attribute.array) { -%>
132132
<% if (attribute.type === 'string') { -%>
133-
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
133+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (index < collection.attributes.length - 1) { %>,<% } %>
134134
<% } else if (attribute.type === 'integer') { -%>
135-
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Int]<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
135+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Int]<% if (index < collection.attributes.length - 1) { %>,<% } %>
136136
<% } else if (attribute.type === 'float') { -%>
137-
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Double]<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
137+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Double]<% if (index < collection.attributes.length - 1) { %>,<% } %>
138138
<% } else if (attribute.type === 'boolean') { -%>
139-
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Bool]<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
139+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Bool]<% if (index < collection.attributes.length - 1) { %>,<% } %>
140140
<% } else { -%>
141-
<%- toCamelCase(attribute.key) %>: (map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [[String: Any]])<% if (!attribute.required) { %>?<% } %>.map { <%- toPascalCase(attribute.type) %>.from(map: $0) }<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
141+
<%- toCamelCase(attribute.key) %>: (map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [[String: Any]])<% if (!attribute.required) { %>?<% } %>.map { <%- toPascalCase(attribute.type) %>.from(map: $0) }<% if (index < collection.attributes.length - 1) { %>,<% } %>
142142
<% } -%>
143143
<% } else { -%>
144144
<% if ((attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') && attribute.format !== 'enum') { -%>
145-
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
145+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (index < collection.attributes.length - 1) { %>,<% } %>
146146
<% } else if (attribute.type === 'string' && attribute.format === 'enum') { -%>
147-
<%- toCamelCase(attribute.key) %>: <%- toPascalCase(attribute.key) %>(rawValue: map["<%- attribute.key %>"] as! String)!<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
147+
<%- toCamelCase(attribute.key) %>: <%- toPascalCase(attribute.key) %>(rawValue: map["<%- attribute.key %>"] as! String)!<% if (index < collection.attributes.length - 1) { %>,<% } %>
148148
<% } else if (attribute.type === 'integer') { -%>
149-
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
149+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (index < collection.attributes.length - 1) { %>,<% } %>
150150
<% } else if (attribute.type === 'float') { -%>
151-
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Double<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
151+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Double<% if (index < collection.attributes.length - 1) { %>,<% } %>
152152
<% } else if (attribute.type === 'boolean') { -%>
153-
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Bool<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
153+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Bool<% if (index < collection.attributes.length - 1) { %>,<% } %>
154154
<% } else { -%>
155-
<%- toCamelCase(attribute.key) %>: <%- toPascalCase(attribute.type) %>.from(map: map["<%- attribute.key %>"] as! [String: Any])<% if (attribute !== collection.attributes.length - 1) { %>,<% } %>
155+
<%- toCamelCase(attribute.key) %>: <%- toPascalCase(attribute.type) %>.from(map: map["<%- attribute.key %>"] as! [String: Any])<% if (index < collection.attributes.length - 1) { %>,<% } %>
156156
<% } -%>
157157
<% } -%>
158158
<% } -%>

0 commit comments

Comments
 (0)