Skip to content

Commit

Permalink
Migrates GPXFileParser to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mmllr committed Nov 4, 2024
1 parent 421985e commit 6809862
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Sources/GPXKit/CombineSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public extension GPXFileParser {
/// /// handle parsing error
/// }
/// ```
class func load(from url: URL) -> AnyPublisher<GPXTrack, GPXParserError> {
static func load(from url: URL) -> AnyPublisher<GPXTrack, GPXParserError> {
guard let parser = GPXFileParser(url: url) else { return Fail(error: GPXParserError.invalidGPX).eraseToAnyPublisher() }
return parser.publisher
}
Expand All @@ -52,7 +52,7 @@ public extension GPXFileParser {
/// /// handle parsing error
/// }
/// ```
class func load(from data: Data) -> AnyPublisher<GPXTrack, GPXParserError> {
static func load(from data: Data) -> AnyPublisher<GPXTrack, GPXParserError> {
guard let parser = GPXFileParser(data: data) else { return Fail(error: GPXParserError.invalidGPX).eraseToAnyPublisher() }
return parser.publisher
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/GPXKit/GPXFileParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ enum GPXAttributes: String {
case longitude = "lon"
}

/// Class for importing a GPX xml to an ``GPXTrack`` value.
public final class GPXFileParser {
/// Struct for importing a GPX xml to an ``GPXTrack`` value.
public struct GPXFileParser: Sendable {
private let xml: String

/// Initializer
Expand Down Expand Up @@ -371,7 +371,7 @@ public extension GPXFileParser {
/// - Parameter url: The url containing the GPX file. See [GPX specification for
/// details](https://www.topografix.com/gpx.asp).
/// - Returns: An `GPXFileParser` instance or nil if the track cannot be parsed.
convenience init?(url: URL) {
init?(url: URL) {
guard let xmlString = try? String(contentsOf: url) else { return nil }
self.init(xmlString: xmlString)
}
Expand All @@ -380,7 +380,7 @@ public extension GPXFileParser {
/// - Parameter data: Data containing the GPX file as encoded xml string. See [GPX specification for
/// details](https://www.topografix.com/gpx.asp).
/// - Returns: An `GPXFileParser` instance or nil if the track cannot be parsed.
convenience init?(data: Data) {
init?(data: Data) {
guard let xmlString = String(data: data, encoding: .utf8) else { return nil }
self.init(xmlString: xmlString)
}
Expand Down

0 comments on commit 6809862

Please sign in to comment.