From 483da52cab1dc939687064a8cc7a9869b6ce329d Mon Sep 17 00:00:00 2001 From: Mickey Reiss Date: Wed, 3 Oct 2018 17:09:51 -0700 Subject: [PATCH] ios: Fix bug in reference arrays (#33) --- langs/ios/ios.go | 7 ++++++- .../TestFiremodelFromSchema/swift/Firemodel.swift | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/langs/ios/ios.go b/langs/ios/ios.go index cc927a8..e31bde5 100644 --- a/langs/ios/ios.go +++ b/langs/ios/ios.go @@ -145,7 +145,12 @@ func toSwiftType(root bool, firetype firemodel.SchemaFieldType) string { } case *firemodel.Array: if firetype.T != nil { - return fmt.Sprintf("[%s]?", toSwiftType(false, firetype.T)) + switch firetype.T.(type) { + case *firemodel.Reference: + return fmt.Sprintf("[%s] = .init()", toSwiftType(false, firetype.T)) + default: + return fmt.Sprintf("[%s]?", toSwiftType(false, firetype.T)) + } } return "[Any]" case *firemodel.File: diff --git a/testfixtures/firemodel/TestFiremodelFromSchema/swift/Firemodel.swift b/testfixtures/firemodel/TestFiremodelFromSchema/swift/Firemodel.swift index a833ec9..531c18c 100644 --- a/testfixtures/firemodel/TestFiremodelFromSchema/swift/Firemodel.swift +++ b/testfixtures/firemodel/TestFiremodelFromSchema/swift/Firemodel.swift @@ -86,9 +86,9 @@ static var testModelId: String = "" // TODO: Add documentation to models in firemodel schema. dynamic var models: [TestStruct]? // TODO: Add documentation to refs in firemodel schema. - dynamic var refs: [Pring.AnyReference]? + dynamic var refs: [Pring.AnyReference] = .init() // TODO: Add documentation to modelRefs in firemodel schema. - dynamic var modelRefs: [Pring.Reference]? + dynamic var modelRefs: [Pring.Reference] = .init() // TODO: Add documentation to meta in firemodel schema. dynamic var meta: [String: Any] = [:] // TODO: Add documentation to metaStrs in firemodel schema.