Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork148
Type-erased wrappers for Encodable, Decodable, and Codable values
License
Flight-School/AnyCodable
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Type-erased wrappers forEncodable,Decodable, andCodable values.
This functionality is discussed in Chapter 3 ofFlight School Guide to Swift Codable.
Add the AnyCodable package to your target dependencies inPackage.swift:
import PackageDescriptionletpackage=Package( name:"YourProject", dependencies:[.package( url:"https://github.com/Flight-School/AnyCodable", from:"0.6.0"),])
Then run theswift build command to build your project.
You can installAnyCodable via CocoaPodsby adding the following line to yourPodfile:
pod'AnyCodable-FlightSchool','~> 0.6.0'
Run thepod install command to download the libraryand integrate it into your Xcode project.
NoteThe module name for this library is "AnyCodable" ---that is, to use it, you add
import AnyCodableto the top of your Swift codejust as you would by any other installation method.The pod is called "AnyCodable-FlightSchool"because there's an existing pod with the name "AnyCodable".
To useAnyCodable in your Xcode project using Carthage,specify it inCartfile:
github "Flight-School/AnyCodable" ~> 0.6.0Then run thecarthage update command to build the framework,and drag the built AnyCodable.framework into your Xcode project.
import AnyCodableletdictionary:[String:AnyEncodable]=["boolean":true,"integer":1,"double":3.141592653589793,"string":"string","array":[1,2,3],"nested":["a":"alpha","b":"bravo","c":"charlie"],"null":nil]letencoder=JSONEncoder()letjson=try! encoder.encode(dictionary)
letjson="""{"boolean": true,"integer": 1,"double": 3.141592653589793,"string":"string","array": [1, 2, 3],"nested": {"a":"alpha","b":"bravo","c":"charlie" },"null": null}""".data(using:.utf8)!letdecoder=JSONDecoder()letdictionary=try! decoder.decode([String:AnyDecodable].self, from: json)
AnyCodable can be used to wrap values for encoding and decoding.
MIT
Mattt (@mattt)
About
Type-erased wrappers for Encodable, Decodable, and Codable values
Topics
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors15
Uh oh!
There was an error while loading.Please reload this page.