Skip to content

Instantly share code, notes, and snippets.

@jimmythai
Created April 12, 2018 11:35
Show Gist options
  • Select an option

  • Save jimmythai/559b062f8e9ecb8ff58fc9e439a486a3 to your computer and use it in GitHub Desktop.

Select an option

Save jimmythai/559b062f8e9ecb8ff58fc9e439a486a3 to your computer and use it in GitHub Desktop.
// 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