diff --git a/Sources/Core/ObjectiveCIR.swift b/Sources/Core/ObjectiveCIR.swift index 0c452ad..0c89b45 100644 --- a/Sources/Core/ObjectiveCIR.swift +++ b/Sources/Core/ObjectiveCIR.swift @@ -424,9 +424,9 @@ public struct ObjCIR { // skip macro in impl return [] case .imports(let classNames, let myName, _): - return [classNames.union(Set([myName])) + let strippedClassNames = Set(classNames.map { $0.trimmingCharacters(in: .whitespaces) }) + return [strippedClassNames.union(Set([myName.trimmingCharacters(in: .whitespaces)])) .sorted() - .map { $0.trimmingCharacters(in: .whitespaces) } .map { ObjCIR.fileImportStmt($0, headerPrefix: params[GenerationParameterType.headerPrefix]) } .joined(separator: "\n")] case .classDecl(name: let className, extends: _, methods: let methods, properties: _, protocols: let protocols): diff --git a/Sources/Core/ObjectiveCNSCodingExtension.swift b/Sources/Core/ObjectiveCNSCodingExtension.swift index a43aacc..c284e9a 100644 --- a/Sources/Core/ObjectiveCNSCodingExtension.swift +++ b/Sources/Core/ObjectiveCNSCodingExtension.swift @@ -11,7 +11,7 @@ import Foundation extension ObjCModelRenderer { func renderInitWithCoder() -> ObjCIR.Method { return ObjCIR.method("- (instancetype)initWithCoder:(NSCoder *)aDecoder") { - [ + let body: [String] = [ self.isBaseClass ? ObjCIR.ifStmt("!(self = [super init])") { ["return self;"] } : "if (!(self = [super initWithCoder:aDecoder])) { return self; }", self.properties.filter { (_, schema) -> Bool in @@ -35,6 +35,7 @@ extension ObjCModelRenderer { }, "return self;", ] + return body } } diff --git a/Tests/CoreTests/ObjectiveCIRTests.swift b/Tests/CoreTests/ObjectiveCIRTests.swift index 896eb1a..c729505 100644 --- a/Tests/CoreTests/ObjectiveCIRTests.swift +++ b/Tests/CoreTests/ObjectiveCIRTests.swift @@ -188,4 +188,11 @@ class ObjectiveCIRTests: XCTestCase { XCTAssertEqual("#import \"include/ModelClass.h\"", ObjCIR.fileImportStmt("ModelClass", headerPrefix: "include/")) XCTAssertEqual("#import \"ModelClass.h\"", ObjCIR.fileImportStmt("ModelClass", headerPrefix: nil)) } + + func testImportsImplementationWithTrailingSpace() { + let imports = ObjCIR.Root.imports(classNames: Set(["MyClass "]), myName: "MyClass", parentName: nil) + let output = imports.renderImplementation(GenerationParameters()) + XCTAssertEqual(1, output.count) + XCTAssertEqual("#import \"MyClass.h\"", output[0]) + } }