All Projects → PhonePe → BetterMappable

PhonePe / BetterMappable

Licence: MIT License
Better Mappable through Property Wrappers using ObjectMapper

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to BetterMappable

Bettersegmentedcontrol
An easy to use, customizable replacement for UISegmentedControl & UISwitch.
Stars: ✭ 1,782 (+6753.85%)
Mutual labels:  carthage, swift-package-manager, swift5
Hippolyte
HTTP Stubbing in Swift
Stars: ✭ 109 (+319.23%)
Mutual labels:  carthage, swift-package-manager, swift5
SSAppUpdater
SSAppUpdater is an open-source framework that compares the current version of the app with the store version and returns the essential details of it like app URL, new app version number, new release note, etc. So you can either redirect or notify the user to update their app.
Stars: ✭ 58 (+123.08%)
Mutual labels:  carthage, swift5, swiftpackagemanager
SwiftGradients
Useful extensions for UIViews and CALayer classes to add beautiful color gradients.
Stars: ✭ 15 (-42.31%)
Mutual labels:  carthage, swift-package-manager, swift5
Dots
Lightweight Concurrent Networking Framework
Stars: ✭ 35 (+34.62%)
Mutual labels:  carthage, swift-package-manager
TVToday
iOS TV Shows app with TMDb Api. RxSwift, MVVM, Clean Architecture. Tuist + Swift Package Manager
Stars: ✭ 27 (+3.85%)
Mutual labels:  swift-package-manager, swift5
SwiftFCXRefresh
Pull to refresh in Swift.
Stars: ✭ 29 (+11.54%)
Mutual labels:  carthage, swift-package-manager
DPVideoMerger-Swift
Multiple videos merge in one video with manage scale & aspect ratio and also merge videos to grid matrix layout for Swift.
Stars: ✭ 49 (+88.46%)
Mutual labels:  carthage, swift5
PagedLists
Paginated UITableView and UICollectionViews for iOS.
Stars: ✭ 69 (+165.38%)
Mutual labels:  swift-package-manager, swift5
MMActionSheet
An actionSheet view implement with pure swift
Stars: ✭ 25 (-3.85%)
Mutual labels:  swift-package-manager, swift5
Mechanica
A cross-platform library of Swift utils to ease your iOS | macOS | watchOS | tvOS and Linux development.
Stars: ✭ 27 (+3.85%)
Mutual labels:  carthage, swift-package-manager
OMJoystick
This is the JoyStick UI library for SwiftUI.
Stars: ✭ 15 (-42.31%)
Mutual labels:  swiftpackage, swiftpackagemanager
AirPlay
Small framework that lets users track iOS AirPlay availability and extra features.
Stars: ✭ 46 (+76.92%)
Mutual labels:  carthage, swift-package-manager
Sqlable
Swift library for making storing data in a SQLite database simple and magic-free
Stars: ✭ 83 (+219.23%)
Mutual labels:  carthage, swift-package-manager
Validated
A rule-based validation framework
Stars: ✭ 31 (+19.23%)
Mutual labels:  carthage, swift-package-manager
core-data-model-description
Declarative way to describe a Core Data model in code.
Stars: ✭ 60 (+130.77%)
Mutual labels:  swift-package-manager, swift5
JSONPreview
🎨 A view that previews JSON in highlighted form, it also provides the ability to format and collapse nodes.
Stars: ✭ 21 (-19.23%)
Mutual labels:  swift-package-manager, swift5
SSCustomPullToRefresh
SSCustomPullToRefresh is an open-source library that uses UIKit to add an animation to the pull to refresh view in a UITableView and UICollectionView.
Stars: ✭ 62 (+138.46%)
Mutual labels:  carthage, swiftpackagemanager
SwiftBuilder
SwiftBuilder is a fast way to assign new value to the property of the object.
Stars: ✭ 26 (+0%)
Mutual labels:  swiftpackage, swiftpackagemanager
swift-package-info
Swift CLI tool that provides information about a Swift Package
Stars: ✭ 65 (+150%)
Mutual labels:  swift-package-manager, swiftpackage

BetterMappable

Swift 5.1 CocoaPods Carthage compatible Swift Package Manager

Better Mappable utilising Swift 5 Property Wrappers is a μframework written on top of ObjectMapper that makes it easy to convert model objects (classes and structs) to and from JSON. Results in reduction of a lot of boiler plate code in models.

Index

JSONProperty

Utilise this property wrapper to map any primitive variables (Int, String, Bool etc...)

struct User: Mappable {
    @JSONProperty var name: String?
    @JSONProperty var age: Int?
    @JSONProperty var onPhonePe: Bool?

    init?(map: Map) {
    }
}

That's it! For those who are familiar with ObjectMapper, yes, you do not have to implement func mapping(map: Map) at all. We automatically take the variable name and assign right value from/to JSON. Incase your variable name is different from the key in the JSON, you can provide it as a parameter in JSONProperty.

@JSONProperty(key: "on_phonepe") 
var onPhonePe: Bool?

You can provide default value to a variable like the way you generally do with ObjectMapper.

@JSONProperty 
var age: Int = 0
    
@JSONProperty(key: "on_phonepe")
var onPhonePe: Bool = false

JSONObject

Use this property wrapper to map custom classes/structs which confirms to Mappable protocol

struct Student: Mappable {
    @JSONObject var address: Address?
    
    @JSONProperty var firstName: String?
    @JSONProperty var lastName: String?
    
    init?(map: Map) {
    }
}

struct Address: Mappable {
    @JSONProperty var street: String?
    @JSONProperty var building: String?
    @JSONProperty var city: String?
    @JSONProperty var state: String?
    
    init?(map: Map) {
        
    }
}

Like the JSONProperty example, if your variable name is different from the key in the JSON, you can provide it as a parameter in JSONObject.

@JSONObject(key: "student_address") 
var address: Address?

JSONObjectArray

Use this property wrapper to map array of custom classes/structs which confirms to Mappable protocol

struct Store: Mappable {
    @JSONObjectArray var transactions: [Transaction]?
    
    @JSONProperty var name: String?
    
    init?(map: Map) {
    }
}

struct Transaction: Mappable {
    @JSONProperty var id: String?
    
    @JSONProperty var amount: Int = 0
    
    init?(map: Map) {
    }
}

JSONObjectDictionary

Use this property wrapper to map dictionary of custom classes/structs which confirms to Mappable protocol

struct Categories: Mappable {
    @JSONObjectDictionary var data: [String: Category]?
    
    init?(map: Map) {
    }
}

struct Category: Mappable {
    @JSONProperty var id: String?
    @JSONProperty var name: String?
    
    init?(map: Map) {
    }
}

JSONObjectDictionaryArrayValue

Use this property wrapper to map dictionary of custom array classes/structs which confirms to Mappable protocol

struct Categories: Mappable {
    @JSONObjectDictionaryArrayValue var data: [String: [Category]]?
    
    init?(map: Map) {
    }
}

struct Category: Mappable {
    @JSONProperty var id: String?
    @JSONProperty var name: String?
    
    init?(map: Map) {
    }
}

JSONPropertyWithTransform

Use this property wrapper to map variables with transformation.

struct Organization: Mappable {
    enum Sector: String {
        case `private` = "PRIVATE"
        case `public` = "PUBLIC"
    }
    
    @JSONPropertyWithTransform(transformer: DateTransform())
    var startDate: Date?
    
    @JSONPropertyWithTransform(transformer: EnumTransform<Sector>())
    var sector: Sector?
    
    @JSONProperty var name: String?
    
    init?(map: Map) {
    }
}

Does this work with StaticMappable?`

Yes it does.

class Vehicle {
    enum VehicleType: String {
        case car = "CAR"
        case bicycle = "BICYCLE"
    }
    
    @JSONProperty var numberOfWheels: Int?
}

extension Vehicle: StaticMappable {
    static func objectForMapping(map: Map) -> BaseMappable? {
        if let rawType = map.JSON["type"] as? String,
            let type = VehicleType(rawValue: rawType) {
            switch type {
            case .car:
                return Car()
                
            case .bicycle:
                return Bicycle()
            }
        }
        
        return nil
    }
}

class Car: Vehicle {
    @JSONProperty var hasBonet: Bool?
}

class Bicycle: Vehicle {
    @JSONProperty var modelName: String?
}

Subclasses

class Base: Mappable {
    @JSONProperty var base: String?
    
    required init?(map: Map) {
    }
}

class Subclass: Base {
    @JSONProperty var sub: String?

    required init?(map: Map) {
        super.init(map: map)
    }
}

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate BetterMappable into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'BetterMappable', '~> 1.0'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate BetterMappable into your Xcode project using Carthage, specify it in your Cartfile:

github "PhonePe/BetterMappable" "1.0.1"

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but BetterMappable does support its use on supported platforms.

Once you have your Swift package set up, adding BetterMappable as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/PhonePe/BetterMappable.git", .upToNextMajor(from: "1.0.0"))
]

Credits

Srikanth KV

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].