Created
April 12, 2018 11:35
-
-
Save jimmythai/559b062f8e9ecb8ff58fc9e439a486a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Somthing like this: | |
| func parseElement(name: String, text: String) { | |
| let trimmed = text.trimmingCharacters(in: .whitespaces) | |
| if name == "trk" { | |
| let t = trimmed | |
| // process element | |
| } else if name == "ele" { | |
| guard let elevation = Int(trimmed) else { return } | |
| } else { | |
| // no need to trim text | |
| } | |
| } | |
| // To this: | |
| func parseElement(name: String, text: String) { | |
| var trimmed: String { text.trimmingCharacters(in: .whitespaces) } | |
| if name == "trk" { | |
| let t = trimmed | |
| // process element | |
| } else if name == "ele" { | |
| guard let elevation = Int(trimmed) else { return } | |
| } else { | |
| // no need to trim text | |
| } | |
| } | |
| // Somthing like this: | |
| while !done && queue.count > 1 && queue[1] != "stop" { | |
| // process the queue | |
| } | |
| // To this: | |
| var canContinue: Bool { return queue.count > 1 && queue[1] != "stop" } | |
| while !done && canContinue { | |
| // process the queue | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment