Latest 0.1.0
Homepage https://github.com/nicholasffox/IdentifierKit
License MIT
Platforms ios 8.0

IdentifierKit

IdentifierKit allows you to easily replace String and Int identifier with strongly typed identifiers.

Features

  • [x] 💪 Strongly typed identifiers
  • [x] 🐟 Full Codeable compatibility

Requirements

  • iOS 8.0+
  • Xcode 9.3
  • Swift 4.1

Installation

CocoaPods

pod 'IdentifierKit'

Carthage

github "NicholasFFox/IdentifierKit"

Swift Package Manager

  • Coming Soon

Usage

Use IdentifierKit to replace weakly typed String and Int identifiers in your model layer with strongly typed identifier objects.

Step 1: Create an unique type to represent your identifier – empty enums work great for this!

enum UserIdentifier: Identifier {}

Step 2: Use a typealias to give yourself syntactic sugar and avoid typing the generic syntax everywhere.

typealias UserId = IntIdentifier<UserIdentifier>

Step 3: Replace your Int (or String) identifer with your newly created type.

struct User: Codable {
  let id: UserId
  let firstName: String
  let lastName: String
}

IdentifierKit works seamlessly with the Codable protocol, so you won’t have to make any changes to your existing JSON.

let json = """
{
  "id": 2,
  "firstName": "Tim",
  "lastName": "Cook"
}
""".data(using: .utf8)!

let user = try JSONDecoder().decode(User.self, from: json)

Thanks

Thanks to Daniel Steinberg for inspiring this framework with your talk on phantom types.

License

IdentifierKit is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "IdentifierKit",
    "version": "0.1.0",
    "summary": "Strongly typed identifiers for your model layer.",
    "description": "Replace your Int/String identifiers with strongly typed Identifier objects.",
    "homepage": "https://github.com/nicholasffox/IdentifierKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "Nick Fox",
    "source": {
        "git": "https://github.com/nicholasffox/IdentifierKit.git",
        "tag": "0.1.0"
    },
    "social_media_url": "https://twitter.com/nickffox",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "IdentifierKit/**/*",
    "swift_version": "4.1"
}

Pin It on Pinterest

Share This