Latest 1.0.0
License MIT
Platforms ios 10.0, osx 10.12


A closure and protocol based framework for ValueTransformer, helpful functions to register ValueTransformer by identifier.

Create a ValueTransformer

Using closures

let transformer = ValueTransformer.closure { object in
   return ...

A ValueTransformer subclass is no more necessary using this method.

Using protocol implementation

Implement ValueTransformerType or ResersableValueTransformerType and an a computed property transformer will be accessible.

Using enum

Define your enum, a list of all your enum case in transformers, implement the function transformedValue of ValueTransformerType protocol

enum StringTransformers: String, ValueTransformers, ValueTransformerType {
    case capitalized, lowercased, uppercased

    public static let transformers: [StringTransformers] = [.capitalized, .lowercased, .uppercased]

    public func transformedValue(_ value: Any?) -> Any? { ../* string manipulation */ }

Register it

You can retrieve a value transformer using optional initializer of ValueTransformer: init?(forName: NSValueTransformerName)

A protocol ValueTransformerRegisterable help you to register your ValueTransformer
By providing a value transformer and an identifier name, a new method will be available


So just defined an identifier name in your ValueTransformerType

struct MyTransformer: ValueTransformerType, ValueTransformerRegisterable {
    var name = NSValueTransformerName(rawValue: "MyTransformation")

For a singleton instance

You can define a singleton instance using ValueTransformerSingleton

struct MyTransformer: ValueTransformerType, ValueTransformerRegisterable, ValueTransformerSingleton {
    var name = NSValueTransformerName(rawValue: "MyTransformation")
    public static let instance = MyTransformer()

or a static function will help you to register it

MyTransformer.register() // same as MyTransformer.instance.register()

For the previous enum example

enum StringTransformers: String, ValueTransformers, ValueTransformerType {
  var name: NSValueTransformerName {
     return NSValueTransformerName("String" + self.rawValue.capitalized)

then you can register one by one


or all case


Some implementations


  • capitalized
  • uppercased
  • lowercased


  • PNG Representation
  • JPEG Representation

Date and Time

  • RFC 2822 Timestamp*
  • Using DateFormatter.Style


  • Using NumberFormatter.Style

Locale component

  • Using NSLocale.Key

Apple Doc


ValueTransformerKit is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "ValueTransformerKit",
    "version": "1.0.0",
    "summary": "A Swift library to play with ValueTransformer",
    "description": "ValueTransformerKit define some useful protocols for `ValueTransformer`.nCreate `ValueTransformer` using closure or protocol implementations.nOr use one of the already implemented.nUse operators between `ValueTransformer`.",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "phimage": "[email protected]"
    "platforms": {
        "ios": "10.0",
        "osx": "10.12"
    "source": {
        "git": "",
        "tag": "1.0.0"
    "source_files": "Sources/*.swift",
    "pushed_with_swift_version": "4.0"

Pin It on Pinterest

Share This