Skip to content

Instantly share code, notes, and snippets.

@deangerber
Created February 18, 2015 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deangerber/93d76b839fff589e922d to your computer and use it in GitHub Desktop.
Save deangerber/93d76b839fff589e922d to your computer and use it in GitHub Desktop.
Feedback for https://github.com/StevenMcD/swift_katas to be pasted into Xcode playground.
// Better class name. Removed unneeded ; from code lines.
class StringCalculator {
// Made class level method
// Removed unneeded () around return value
class func add(numbers: String) -> Int {
// Removed unneeded () around if condition
if numbers.isEmpty {
return 0
}
// No need to cast. String has method to create int value. Returns optional so forcing unwrap. Not the nicest but simplest.
return numbers.toInt()!
}
}
// Not sure how to call test from playground so simple value checking.
StringCalculator.add("") == 0
StringCalculator.add("1") == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment