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
- Host: GitHub
- URL: https://github.com/swiftuiux/some-codable-swift
- Owner: swiftuiux
- License: mit
- Created: 2023-03-10T11:40:42.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-27T11:01:54.000Z (over 1 year ago)
- Last Synced: 2025-04-08T20:22:58.491Z (8 months ago)
- Topics: any, codable
- Language: Swift
- Homepage:
- Size: 13.7 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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}*