Skip to content

How To: Deal with Extensions

Vincent Neo edited this page Feb 19, 2021 · 1 revision

Dealing with Extensions

Extensions in GPX files are represented as GPXExtensions in CoreGPX.

Accessing GPX Files's extensions

Once a GPX file is parsed, you can access the extensions, by using subscript, with the tag name.

  • Use extensions["tagNameHere"] to get a GPXExtensionElement, which will contain various data parsed. Alternatively, use get(from parent: String?) to get a dictionary of extension data parsed.

Writing GPX extensions

  • Firstly, initialize GPXRoot using init(withExtensionAttributes:, schemaLocation:) to initialize with extension schema information on the main gpx header tag.
  • Secondly, initialize GPXExtensions whenever needed, to be added to the GPXRoot/or other elements, when needed.
  • Use function append(at parent: String?, contents: [String : String]) to write extension data. If no parent, use nil.

To know more, please do read the documentation for GPXExtensions and GPXExtensionsElement.