项目作者: jimlai586

项目描述 :
A JSON wrapper that covers most-frequent usages
高级语言: Swift
项目地址: git://github.com/jimlai586/MagicJSON.git
创建时间: 2019-04-04T11:01:57Z
项目社区:https://github.com/jimlai586/MagicJSON

开源协议:MIT License

下载


MagicJSON

A JSON wrapper that covers most-frequent usages

Magic

Things that SwiftyJSON did not cover

SwiftyJSON is great, but it does not support the most important usage in development.

  1. enum P: String, Codable {
  2. case someKey
  3. }
  4. let pj = [P.someKey: "some value"]
  5. let json = JSON(pj)
  6. print(json[P.someKey]) // should print "some value"

Sure you can add extension to support it, but it’d be cubersome in some cases.

This one-file library covers all common usages of SwiftyJSON with additional support for enum key.

Usage

declare your enum, and make it conform to JSONKey

e.g.;

  1. enum P: String, Codable, JSONKey {...}

then use it for subscript

  1. let mj = MJ([P.someKey: [P.someKey: [0, 1, 2, 3, 4, 5]]])
  2. print(mj[P.someKey][P.someKey][3].intValue) // should print 3

It should work as SwiftyJSON in most-frequent usages.

But this might not work for you if you use SwiftyJSON very differently.

Installation

Copy one source file over.

Further updates

Write this in playground, may miss something. Update later when I find it.