Skip to content

Commit

Permalink
Optimise GPXRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentneo committed Jan 23, 2019
1 parent 37bcc4d commit a808209
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions Classes/GPXRoot.swift
Expand Up @@ -55,12 +55,8 @@ open class GPXRoot: GPXElement {
}

public func add(waypoint: GPXWaypoint?) {
if waypoint != nil {
let contains = waypoints.contains(waypoint!)
if contains == false {
waypoint?.parent = self
waypoints.append(waypoint!)
}
if let validWaypoint = waypoint {
self.waypoints.append(validWaypoint)
}
}

Expand All @@ -73,7 +69,7 @@ open class GPXRoot: GPXElement {
if contains == true {
waypoint.parent = nil
if let index = waypoints.firstIndex(of: waypoint) {
waypoints.remove(at: index)
self.waypoints.remove(at: index)
}
}
}
Expand All @@ -87,12 +83,8 @@ open class GPXRoot: GPXElement {
}

public func add(route: GPXRoute?) {
if route != nil {
let contains = routes.contains(route!)
if contains == false {
route?.parent = self
routes.append(route!)
}
if let validRoute = route {
self.routes.append(validRoute)
}
}

Expand All @@ -105,7 +97,7 @@ open class GPXRoot: GPXElement {
if contains == true {
route.parent = nil
if let index = routes.firstIndex(of: route) {
waypoints.remove(at: index)
self.waypoints.remove(at: index)
}
}
}
Expand All @@ -117,12 +109,8 @@ open class GPXRoot: GPXElement {
}

public func add(track: GPXTrack?) {
if track != nil {
let contains = tracks.contains(track!)
if contains == false {
track?.parent = self
tracks.append(track!)
}
if let validTrack = track {
self.tracks.append(validTrack)
}
}

Expand All @@ -135,7 +123,7 @@ open class GPXRoot: GPXElement {
if contains == true {
track.parent = nil
if let index = tracks.firstIndex(of: track) {
waypoints.remove(at: index)
self.waypoints.remove(at: index)
}
}
}
Expand Down

0 comments on commit a808209

Please sign in to comment.