Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wolfmcnally/wolfanycodable
Swift type-erased wrappers for Encodable, Decodable, and Codable values.
https://github.com/wolfmcnally/wolfanycodable
Last synced: 26 days ago
JSON representation
Swift type-erased wrappers for Encodable, Decodable, and Codable values.
- Host: GitHub
- URL: https://github.com/wolfmcnally/wolfanycodable
- Owner: wolfmcnally
- License: mit
- Created: 2018-09-14T00:33:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-10T02:53:12.000Z (over 5 years ago)
- Last Synced: 2024-03-15T01:01:11.377Z (10 months ago)
- Language: Swift
- Size: 24.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WolfAnyCodable
Swift type-erased wrappers for Encodable, Decodable, and Codable values.
This cocoapod exists to easily incorporate the functionality of [AnyCodable](https://github.com/Flight-School/AnyCodable).
This functionality is discussed in Chapter 3 of [Flight School Guide to Swift Codable](https://gumroad.com/l/codable).
## AnyEncodable
```swift
import AnyCodablelet dictionary: [String: AnyEncodable] = [
"boolean": true,
"integer": 1,
"double": 3.14159265358979323846,
"string": "string",
"array": [1, 2, 3],
"nested": [
"a": "alpha",
"b": "bravo",
"c": "charlie"
]
]let encoder = JSONEncoder()
let json = try! encoder.encode(dictionary)
```## AnyDecodable
```swift
let json = """
{
"boolean": true,
"integer": 1,
"double": 3.14159265358979323846,
"string": "string",
"array": [1, 2, 3],
"nested": {
"a": "alpha",
"b": "bravo",
"c": "charlie"
}
}
""".data(using: .utf8)!let decoder = JSONDecoder()
let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json)
```## AnyCodable
`AnyCodable` can be used to wrap values for encoding and decoding.
## License
MIT
## Original Author
Mattt ([@mattt](https://twitter.com/mattt))
## Requirements
Swift 4.2
## Installation
WolfAnyCodable is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'WolfAnyCodable'
```## Author
Wolf McNally, [email protected]
## License
WolfAnyCodable is available under the MIT license. See the LICENSE file for more info.