Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Type-erased wrappers for Encodable, Decodable, and Codable values

License

NotificationsYou must be signed in to change notification settings

Flight-School/AnyCodable

Repository files navigation

Build StatusLicenseSwift VersionCocoapods platformsCocoapods compatibleCarthage compatible

Type-erased wrappers forEncodable,Decodable, andCodable values.

This functionality is discussed in Chapter 3 ofFlight School Guide to Swift Codable.

Installation

Swift Package Manager

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.

CocoaPods

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 addimport AnyCodable to 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".

Carthage

To useAnyCodable in your Xcode project using Carthage,specify it inCartfile:

github "Flight-School/AnyCodable" ~> 0.6.0

Then run thecarthage update command to build the framework,and drag the built AnyCodable.framework into your Xcode project.

Usage

AnyEncodable

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)

AnyDecodable

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

AnyCodable can be used to wrap values for encoding and decoding.

License

MIT

Contact

Mattt (@mattt)

About

Type-erased wrappers for Encodable, Decodable, and Codable values

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Contributors15

    Languages


    [8]ページ先頭

    ©2009-2026 Movatter.jp