Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Core/ObjectiveCIR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion Sources/Core/ObjectiveCNSCodingExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +35,7 @@ extension ObjCModelRenderer {
},
"return self;",
]
return body
}
}

Expand Down
7 changes: 7 additions & 0 deletions Tests/CoreTests/ObjectiveCIRTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}