@@ -55,12 +55,8 @@ open class GPXRoot: GPXElement {
55
55
}
56
56
57
57
public func add( waypoint: GPXWaypoint ? ) {
58
- if waypoint != nil {
59
- let contains = waypoints. contains ( waypoint!)
60
- if contains == false {
61
- waypoint? . parent = self
62
- waypoints. append ( waypoint!)
63
- }
58
+ if let validWaypoint = waypoint {
59
+ self . waypoints. append ( validWaypoint)
64
60
}
65
61
}
66
62
@@ -73,7 +69,7 @@ open class GPXRoot: GPXElement {
73
69
if contains == true {
74
70
waypoint. parent = nil
75
71
if let index = waypoints. firstIndex ( of: waypoint) {
76
- waypoints. remove ( at: index)
72
+ self . waypoints. remove ( at: index)
77
73
}
78
74
}
79
75
}
@@ -87,12 +83,8 @@ open class GPXRoot: GPXElement {
87
83
}
88
84
89
85
public func add( route: GPXRoute ? ) {
90
- if route != nil {
91
- let contains = routes. contains ( route!)
92
- if contains == false {
93
- route? . parent = self
94
- routes. append ( route!)
95
- }
86
+ if let validRoute = route {
87
+ self . routes. append ( validRoute)
96
88
}
97
89
}
98
90
@@ -105,7 +97,7 @@ open class GPXRoot: GPXElement {
105
97
if contains == true {
106
98
route. parent = nil
107
99
if let index = routes. firstIndex ( of: route) {
108
- waypoints. remove ( at: index)
100
+ self . waypoints. remove ( at: index)
109
101
}
110
102
}
111
103
}
@@ -117,12 +109,8 @@ open class GPXRoot: GPXElement {
117
109
}
118
110
119
111
public func add( track: GPXTrack ? ) {
120
- if track != nil {
121
- let contains = tracks. contains ( track!)
122
- if contains == false {
123
- track? . parent = self
124
- tracks. append ( track!)
125
- }
112
+ if let validTrack = track {
113
+ self . tracks. append ( validTrack)
126
114
}
127
115
}
128
116
@@ -135,7 +123,7 @@ open class GPXRoot: GPXElement {
135
123
if contains == true {
136
124
track. parent = nil
137
125
if let index = tracks. firstIndex ( of: track) {
138
- waypoints. remove ( at: index)
126
+ self . waypoints. remove ( at: index)
139
127
}
140
128
}
141
129
}
0 commit comments