Skip to content

Commit 34aacc2

Browse files
author
Alex Oakley
authored
Merge pull request #1 from sublabdev/dev
Initial release
2 parents 79d507b + 5159b91 commit 34aacc2

File tree

355 files changed

+21846
-1478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

355 files changed

+21846
-1478
lines changed

Doc/ScaleCoder.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
### ScaleCoder Example
2+
3+
Bellow is provided an example of `ScaleCoder`'s creation and usage which decodes and encodes any type, conforming to `Codable`.
4+
5+
## Initialization
6+
7+
You can use the default way of creating it:
8+
9+
```Swift
10+
let coder = ScaleCoder.defaultCoder()
11+
```
12+
The above method uses `DefaultScaleCodecAdapterProvider` under the hood
13+
which supports all the basic `Codable` types out of a box as well as some
14+
custom ones, including: `struct`; `Int128`; `Int256`; `Int512`; `UInt128`; `UInt256` etc.
15+
16+
On the other hand, you can create your custom one:
17+
18+
```Swift
19+
let adapterProvider = ScaleCodecAdapterProvider()
20+
adapterProvider.setAdapter(adapter:for:)
21+
let encoder = ScaleEncoder(adapterProvider: adapterProvider)
22+
let decoder = ScaleDecoder(adapterProvider: adapterProvider)
23+
let coder = ScaleCoder(encoder: encoder, decoder: decoder)
24+
```
25+
Note that in the above-mentioned case you have to manually set an adapter for your `Codable` type.
26+
The library includes adapters for all the basic `Swift` types as well as for custom ones like:
27+
`struct`; `Int128`; `Int256`; `Int512`; `UInt128`; `UInt256`; `UInt512`; `BigUInt` etc.
28+
29+
*Note:* For all standard numeric types (`Int`; `Int16`; `UInt32` etc.) `NumericAdapter` class should be used.
30+
31+
## Usage
32+
33+
After creating a coder object, it can be to encode (or decode) types (or to types), conforming to `Codable`.
34+
35+
```Swift
36+
let initialValue = "Some String"
37+
let encodedValue = coder.encoder.encode(initialValue)
38+
let decodedValue = coder.decoder.decode(String.self, from: encodedValue)
39+
```
40+
41+
Here we try to encode and after that to decode a `String` value. The `decodedValue` will be equal to `initialValue`.

Example/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### CocoaPods ###
2+
Pods/
3+
4+
## User settings
5+
xcuserdata/

Example/Podfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use_frameworks!
22

3-
platform :ios, '10.0'
3+
platform :ios, '13.0'
44

55
target 'ScaleCodecSwift_Example' do
66
pod 'ScaleCodecSwift', :path => '../'
7+
pod 'CommonSwift', :git => 'https://github.com/sublabdev/common-swift.git', :branch => 'dev'
8+
pod 'BigInt'
79

810
target 'ScaleCodecSwift_Tests' do
911
inherit! :search_paths

Example/Podfile.lock

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
PODS:
2-
- ScaleCodecSwift (0.1.0)
2+
- BigInt (5.0.0)
3+
- CommonSwift (1.0.0):
4+
- BigInt (~> 5.0.0)
5+
- ScaleCodecSwift (1.0.0):
6+
- BigInt (~> 5.0.0)
7+
- CommonSwift
38

49
DEPENDENCIES:
10+
- BigInt
11+
- CommonSwift (from `https://github.com/sublabdev/common-swift.git`, branch `dev`)
512
- ScaleCodecSwift (from `../`)
613

14+
SPEC REPOS:
15+
trunk:
16+
- BigInt
17+
718
EXTERNAL SOURCES:
19+
CommonSwift:
20+
:branch: dev
21+
:git: https://github.com/sublabdev/common-swift.git
822
ScaleCodecSwift:
923
:path: "../"
1024

25+
CHECKOUT OPTIONS:
26+
CommonSwift:
27+
:commit: 24cc1514dedb0755a86ae8b6752778a4ff54fb95
28+
:git: https://github.com/sublabdev/common-swift.git
29+
1130
SPEC CHECKSUMS:
12-
ScaleCodecSwift: 179b6ddc31bb8528d380fd19166a2a9fddc03e86
31+
BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8
32+
CommonSwift: ad350f0e06c040e5cb660cd7154f947851c73fbd
33+
ScaleCodecSwift: 2fa35cbc70c5634fdc0960cc6c712e917b2c688c
1334

14-
PODFILE CHECKSUM: eef510782536c545ce866fb495ea308eae3f0286
35+
PODFILE CHECKSUM: 1a95faa77d7a036005bcfe079d3f5c22b423b9c7
1536

1637
COCOAPODS: 1.11.3

Example/Pods/Local Podspecs/ScaleCodecSwift.podspec.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

Example/Pods/Manifest.lock

Lines changed: 0 additions & 16 deletions
This file was deleted.

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 0 additions & 776 deletions
This file was deleted.

Example/Pods/Target Support Files/Pods-ScaleCodecSwift_Example/Pods-ScaleCodecSwift_Example-Info.plist

Lines changed: 0 additions & 26 deletions
This file was deleted.

Example/Pods/Target Support Files/Pods-ScaleCodecSwift_Example/Pods-ScaleCodecSwift_Example-acknowledgements.markdown

Lines changed: 0 additions & 26 deletions
This file was deleted.

Example/Pods/Target Support Files/Pods-ScaleCodecSwift_Example/Pods-ScaleCodecSwift_Example-acknowledgements.plist

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)