@@ -3,7 +3,7 @@ const { AttributeType } = require('../attribute');
3
3
const { LanguageMeta } = require("./language");
4
4
5
5
class Swift extends LanguageMeta {
6
- getType(attribute) {
6
+ getType(attribute, collections ) {
7
7
let type = "";
8
8
switch (attribute.type) {
9
9
case AttributeType.STRING:
@@ -24,7 +24,8 @@ class Swift extends LanguageMeta {
24
24
type = "Bool";
25
25
break;
26
26
case AttributeType.RELATIONSHIP:
27
- type = LanguageMeta.toPascalCase(attribute.relatedCollection);
27
+ const relatedCollection = collections.find(c => c.$id === attribute.relatedCollection);
28
+ type = LanguageMeta.toPascalCase(relatedCollection.name);
28
29
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
29
30
type = `[${type}]`;
30
31
}
@@ -63,7 +64,7 @@ public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
63
64
<% } -%>
64
65
public class <% - toPascalCase(collection.name) %> : Codable {
65
66
<% for (const attribute of collection.attributes) { -%>
66
- public let <% - strict ? toCamelCase(attribute.key) : attribute.key %> : <% - getType(attribute) %>
67
+ public let <% - strict ? toCamelCase(attribute.key) : attribute.key %> : <% - getType(attribute, collections ) %>
67
68
<% } %>
68
69
enum CodingKeys: String, CodingKey {
69
70
<% for (const attribute of collection.attributes) { -%>
@@ -73,7 +74,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
73
74
74
75
public init(
75
76
<% for (const [index, attribute] of Object .entries(collection.attributes)) { -%>
76
- <% - strict ? toCamelCase(attribute.key) : attribute.key %> : <% - getType(attribute) %><% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
77
+ <% - strict ? toCamelCase(attribute.key) : attribute.key %> : <% - getType(attribute, collections ) %><% if (index < collection.attributes.length - 1 ) { %> ,<% } %>
77
78
<% } -%>
78
79
) {
79
80
<% for (const attribute of collection.attributes) { -%>
@@ -86,9 +87,9 @@ public class <%- toPascalCase(collection.name) %>: Codable {
86
87
87
88
<% for (const attribute of collection.attributes) { -%>
88
89
<% if (!(!attribute.required && attribute.default === null)) { -%>
89
- self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<% - getType(attribute).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
90
+ self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<% - getType(attribute, collections ).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
90
91
<% } else { -%>
91
- self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<% - getType(attribute).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
92
+ self.<% - strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<% - getType(attribute, collections ).replace(' ?' , ' ' ) %> .self, forKey: .<% - strict ? toCamelCase(attribute.key) : attribute.key %> )
92
93
<% } -%>
93
94
<% } -%>
94
95
}
0 commit comments