mirror of
https://github.com/Dev1an/MsgPack.git
synced 2026-03-25 08:45:55 +00:00
Add custom type to readme
This commit is contained in:
parent
c57ed19c62
commit
9c06dd51a8
1 changed files with 8 additions and 0 deletions
|
|
@ -3,11 +3,19 @@
|
||||||
```swift
|
```swift
|
||||||
import MsgPack
|
import MsgPack
|
||||||
|
|
||||||
|
// Encode standard types
|
||||||
let encoder = Encoder()
|
let encoder = Encoder()
|
||||||
try encoder.encode("Hello world")
|
try encoder.encode("Hello world")
|
||||||
try encoder.encode("😇")
|
try encoder.encode("😇")
|
||||||
try encoder.encode(0x0102030405060708)
|
try encoder.encode(0x0102030405060708)
|
||||||
try encoder.encode(["Some strings", "in an array"])
|
try encoder.encode(["Some strings", "in an array"])
|
||||||
|
|
||||||
|
// Encode custom types with Encodable 🎉
|
||||||
|
struct Point: Encodable {
|
||||||
|
let x: Int
|
||||||
|
let y: Int
|
||||||
|
}
|
||||||
|
try encoder.encode(Point(x: 90, y: 45))
|
||||||
```
|
```
|
||||||
|
|
||||||
Take a look at the [playground](Playground.playground/Contents.swift) for more examples.
|
Take a look at the [playground](Playground.playground/Contents.swift) for more examples.
|
||||||
Loading…
Reference in a new issue