Skip to content

Instantly share code, notes, and snippets.

@moshegutman
Last active November 19, 2017 21:39
Show Gist options
  • Save moshegutman/5e91f6b892f5ac1e4fbedc86c95e58f9 to your computer and use it in GitHub Desktop.
Save moshegutman/5e91f6b892f5ac1e4fbedc86c95e58f9 to your computer and use it in GitHub Desktop.
An NSFormatter subclass written in Swift for converting strings to uppercase.
import Foundation
class UppercaseFormatter : Formatter {
override func string(for obj: Any?) -> String? {
if let stringValue = obj as? String {
return stringValue.uppercased()
}
return nil
}
override func getObjectValue(_ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?, for string: String, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool {
obj?.pointee = string as AnyObject
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment