GPXFileParser

public final class GPXFileParser

Class for importing a GPX xml to an GPXTrack value.

  • Initializer

    Declaration

    Swift

    public init(xmlString: String)

    Parameters

    xmlString

    The GPX xml string. See GPX specification for details.

  • Parses the GPX xml.

    Declaration

    Swift

    public func parse(elevationSmoothing: ElevationSmoothing = .none) -> Result<GPXTrack, GPXParserError>

    Parameters

    elevationSmoothing

    The ElevationSmoothing in meters for the grade segments. Defaults to none.

    Return Value

    A Result of the GPXTrack in the success or an GPXParserError in the failure case.

  • Publisher for bridging into Combine.

    An AnyPublisher with Output GPXTrack and Failure of GPXParserError.

    Declaration

    Swift

    public var publisher: AnyPublisher<GPXTrack, GPXParserError> { get }
  • Helper for loading a gpx track from an url.

    let url = // ... url with GPX file
    GPXFileParser
       .load(from: url)
       .map { track in
            // do something with track
       }
       .catch {
           /// handle parsing error
       }
    

    Declaration

    Swift

    public class func load(from url: URL) -> AnyPublisher<GPXTrack, GPXParserError>

    Parameters

    url

    The url of the GPX file. See GPX specification for details.

    Return Value

    An AnyPublisher with Output GPXTrack and Failure of GPXParserError.

  • Helper for loading a gpx track from data.

    let data = xmlString.data(using: .utf8)
    GPXFileParser
       .load(from: data)
       .map { track in
            // do something with track
       }
       .catch {
           /// handle parsing error
       }
    

    Declaration

    Swift

    public class func load(from data: Data) -> AnyPublisher<GPXTrack, GPXParserError>

    Parameters

    data

    The data containing the GPX as xml. See GPX specification for details.

    Return Value

    An AnyPublisher with Output GPXTrack and Failure of GPXParserError.

  • Convenience initialize for loading a GPX file from an url. Fails if the track cannot be parsed.

    Declaration

    Swift

    convenience init?(url: URL)

    Parameters

    url

    The url containing the GPX file. See GPX specification for details.

    Return Value

    An GPXFileParser instance or nil if the track cannot be parsed.

  • Convenience initialize for loading a GPX file from a data. Returns nil if the track cannot be parsed.

    Declaration

    Swift

    convenience init?(data: Data)

    Parameters

    data

    Data containing the GPX file as encoded xml string. See GPX specification for details.

    Return Value

    An GPXFileParser instance or nil if the track cannot be parsed.