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 tonone
.Return Value
A
Result
of theGPXTrack
in the success or anGPXParserError
in the failure case. -
Publisher for bridging into Combine.
An AnyPublisher with Output
GPXTrack
and Failure ofGPXParserError
.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 ofGPXParserError
. -
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 ofGPXParserError
. -
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.