An open API service indexing awesome lists of open source software.

https://github.com/swiftuiux/some-codable-swift

Type that can encode itself to an external representation from different types AnyCodable Some any codable
https://github.com/swiftuiux/some-codable-swift

any codable

Last synced: 6 months ago
JSON representation

Type that can encode itself to an external representation from different types AnyCodable Some any codable

Awesome Lists containing this project

README

          

# SomeCodable
## Subsidiary package

### SomeEncodable
A type that can encode itself to an external representation from different types.

```swift
struct User: Encodable{
let name: String
}
let arr : [SomeEncodable] = [
.init(User(name: "User")), 640, 20.65, "DPMSolverMultistep"
]

if let encode = try? JSONEncoder().encode(arr){
let str = String(decoding: encode, as: UTF8.self)
print(str)
}
```
*[{"name":"User"},640,20.65,"DPMSolverMultistep"]*

```swift
struct User: Encodable{
let name: String
}
let dic : [String: SomeEncodable] = [
"data" : .init(User(name: "User")), "width" : 640, "num_inference_steps" : 20.65
]

if let encode = try? JSONEncoder().encode(dic){
let str = String(decoding: encode, as: UTF8.self)
print(str)
}

```

*{"width":640,"data":{"name":"User"},"num_inference_steps":20.65}*