Code Monkey home page Code Monkey logo

dictionarycoding's Introduction

Test results Latest release swift 5.0 shield swift dev shield Platforms: macOS, iOS, tvOS, watchOS

Test results Latest release Swift 5.0 Platforms: iOS, macOS, tvOS, watchOS, Linux

DictionaryCoding

This is an implementation of Swift's Encoder/Decoder protocols which uses NSDictionary as its underlying container mechanism.

It allows you to take a native swift class or struct that confirms to the Codable protocol and convert it to, or initialise it from, a dictionary.

A lot of the code is actually taken from the Swift Foundation library's own JSONEncoder and JSONDecoder classes.

It turns out that those class actually work by using NSDictionary as an intermediate step between JSON and the native type to be encoded/decoded. Unfortunately the underlying NSDictionary support isn't exposed by Foundation, which is why I've done so here.

See this blog post for a bit more detail!

Build Instructions

At the moment this module is best built using the Swift Package Manager with swift build.

The unit tests can be run with swift test.

An Xcode project can be generated with swift package generate-xcodeproj --xcconfig-overrides DictionaryCoding.xcconfig.

A CocoaPods .podspec file is included. I don't use CocoaPods myself though, so I can't be entirely sure that I haven't broken something (or forgotten to update something).

Please file issues (or even better, pull requests) for support for other build systems.

dictionarycoding's People

Contributors

azalan avatar jnewc avatar junebash avatar max-potapov avatar samdeane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dictionarycoding's Issues

Push latest releases to cocoapods

Howdy!

Great project, really useful functionality for some of my apps! Big koodos for this!

I noticed that 1.0.9 is released, but it's not available on Cocoapods. In fact, Cocoapods is listing 1.0.6 as the latest version (https://cocoapods.org/pods/DictionaryCoding).
I'm wondering if the latest releases could be pushed to the main Cocoapods repo?

Enhancement: Decode Swift Array

As indicated in blog:

one obvious enhancement would be to add a parallel implementation which works natively with swift arrays and dictionaries.

This will help me to avoid boiler plate of decoding arrays nested in dictionaries.

Wish to use DictionaryCoding
to parse Array of Dictionaries to array of my models

Thank you!

add xcconfig file

add a settings file which can be used when regenerating the xcode project:

swift package generate-xcodeproj --xcconfig-overrides Settings.xcconfig

This will allow us to set things like the deployment target.

add linux to travis tests

In order to do #13, we need to be able to test on Linux.

Of course, the current implementation makes heavy use of NSDictionary / NSValue, so a Linux build isn't going to fly until that's sorted out.

iOS Support?

Is there a reason why the podspec only allows macOS use? I'd like to be able to incorporate this pod in an iOS project.

parameterise the implementation to work with NSDictionary or Dictionary

The current implementation is largely based on NSDictionary (as it's derived from the NSJSONCoding code).

It would be good to be able to build a version that just uses Dictionary, in order to:

  • build on Linux
  • be more efficient if we're just living in a swift-only universe

That said, it would still be more efficient to be able to use something like the current code when reading from / writing to NSDictionary.

One way that this might be achieved is to restructure the code to take a generic dictionary type, and then to provide boxing/unboxing implementations for both cases.

EXEC_BAD_ACCESS when encoding dates

When encoding Date objects, it crashes with a EXEC_BAD_ACESS in
fileprivate func box_<T : Encodable>(_ value: T) throws -> NSObject? {
(DictionaryEncoder.swift, line 810).

It's reproducable with the delivered unit tests:
testEncodingDateFormats()

Xcode 10.1
Swift 4
Deployment target 11.0

Fix Linux Build

Tests are failing for the Linux build with my standard Tests.yml setup.

Need to look into this...

Minimum deployment target for iOS

I have added the library to my iOS project using Carthage, but Xcode says

Module file's minimum deployment target is ios11.4 v11.4

Is there a reason for that? The code looks like it should build and work also with older versions (my minimum is 10.0).

Linux-friendly implementation

In order to build on Linux we need to remove references to NSObject etc.

There are three potential approaches:

  • use the CF types instead
  • just use Swift types
  • parameterise the implementation and make one with NSDictionary, one with Dictionary (#12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.