Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.