From ad2510894e82fff8d114cf602ebba2c9dd329a44 Mon Sep 17 00:00:00 2001 From: Vincent Neo <23420208+vincentneo@users.noreply.github.com> Date: Fri, 1 Nov 2019 21:48:21 +0800 Subject: [PATCH] fix for #58 comment --- Classes/GPXExtensionsElement.swift | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Classes/GPXExtensionsElement.swift b/Classes/GPXExtensionsElement.swift index 0c3fe81..bc33783 100644 --- a/Classes/GPXExtensionsElement.swift +++ b/Classes/GPXExtensionsElement.swift @@ -57,25 +57,24 @@ open class GPXExtensionsElement: GPXElement, Codable { override func addOpenTag(toGPX gpx: NSMutableString, indentationLevel: Int) { let attribute = NSMutableString() - for (key, value) in attributes { - attribute.appendFormat(" %@=\"%@\"", key, value) + if !attributes.isEmpty { + for (key, value) in attributes { + attribute.appendFormat(" %@=\"%@\"", key, value) + } + gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute) + } + else if let text = text { + self.addProperty(forValue: text, gpx: gpx, tagName: tagName(), indentationLevel: indentationLevel) } - gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute) } override func addChildTag(toGPX gpx: NSMutableString, indentationLevel: Int) { super.addChildTag(toGPX: gpx, indentationLevel: indentationLevel) - if let text = text { - self.addProperty(forValue: text, gpx: gpx, tagName: tagName(), indentationLevel: indentationLevel) - } + for child in children { - if let text = child.text { - self.addProperty(forValue: text, gpx: gpx, tagName: child.tagName(), indentationLevel: indentationLevel) - } - else { - child.gpx(gpx, indentationLevel: indentationLevel) - } + child.gpx(gpx, indentationLevel: indentationLevel) } } + }