File tree Expand file tree Collapse file tree 1 file changed +70
-0
lines changed
Expand file tree Collapse file tree 1 file changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -8,3 +8,73 @@ Text Encoding for Swift
88### Current features
99- Base64 encoding
1010- Hex encoding
11+
12+ ### Usage
13+
14+ Import ` SwiftEncoding ` to your ` Package.swift ` as a dependency
15+
16+ ``` swift
17+ // swift-tools-version: 5.7
18+ // The swift-tools-version declares the minimum version of Swift required to build this package.
19+
20+ import PackageDescription
21+
22+ let package = Package (
23+ name : " MyApp" ,
24+ dependencies : [
25+ .package (url : " https://github.com/telkomdev/SwiftEncoding.git" , from : " 1.0.0" ),
26+ ],
27+ targets : [
28+ .executableTarget (
29+ name : " MyApp" ,
30+ dependencies : [
31+ .byName (name : " SwiftEncoding" )
32+ ]),
33+ .testTarget (
34+ name : " MyAppTests" ,
35+ dependencies : [" MyApp" ]),
36+ ]
37+ )
38+ ```
39+
40+ Encode text with ` Base64 `
41+ ``` swift
42+ import SwiftEncoding
43+
44+ @main
45+ public struct App {
46+
47+ public static func main () {
48+ let base64EncodeRes = encodeBase64 (data : " swift is cool" )
49+ print (base64EncodeRes)
50+
51+ do {
52+ let base64DecodeRes = try decodeBase64 (data : base64EncodeRes)
53+ print (base64DecodeRes)
54+ } catch {
55+ print (" base64 decode error" )
56+ }
57+ }
58+ }
59+ ```
60+
61+ Encode text with ` Hex `
62+ ``` swift
63+ import SwiftEncoding
64+
65+ @main
66+ public struct App {
67+
68+ public static func main () {
69+ let hexEncodeRes = encodeHex (data : " swift is cool" )
70+ print (hexEncodeRes)
71+
72+ do {
73+ let hexDecodeRes = try decodeHex (data : hexEncodeRes)
74+ print (hexDecodeRes)
75+ } catch {
76+ print (" hex decode error" )
77+ }
78+ }
79+ }
80+ ```
You can’t perform that action at this time.
0 commit comments