Skip to content

Instantly share code, notes, and snippets.

@iskeld
Last active May 26, 2016 07:33
Show Gist options
  • Save iskeld/a6ba57b145f2f9208fa63efc69d2c517 to your computer and use it in GitHub Desktop.
Save iskeld/a6ba57b145f2f9208fa63efc69d2c517 to your computer and use it in GitHub Desktop.
Swift base class exceptions
/*
* Code to my question http://stackoverflow.com/questions/37448249/propagating-base-class-errors-in-swift
* I don't understand why there's such a difference in these two Formatters behavior
*/
import Cocoa
class OverridenFormatter: NSNumberFormatter {
override func getObjectValue(obj: AutoreleasingUnsafeMutablePointer<AnyObject?>, forString string: String, range rangep: UnsafeMutablePointer<NSRange>) throws {
// not doing anything, just delegating to the base class
try super.getObjectValue(obj, forString: string, range: rangep)
}
}
class NonOverridenFormatter: NSNumberFormatter {}
let nonOverridenformatter = NonOverridenFormatter()
let overridenFormatter = OverridenFormatter()
nonOverridenformatter.minimum = 15
overridenFormatter.minimum = 15
// WHY these calls yield different results ?
nonOverridenformatter.numberFromString("14") // return nil
overridenFormatter.numberFromString("14") // throws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment