Skip to content

Commit b45da43

Browse files
committed
Json
0 parents  commit b45da43

File tree

11 files changed

+1269
-0
lines changed

11 files changed

+1269
-0
lines changed

Package.resolved

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// swift-tools-version:5.3
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "Json",
8+
products: [
9+
// Products define the executables and libraries a package produces, and make them visible to other packages.
10+
.library(
11+
name: "Json",
12+
targets: ["Json"]),
13+
],
14+
dependencies: [
15+
// Dependencies declare other packages that this package depends on.
16+
.package(url: "https://github.com/Quick/Quick.git", from: "4.0.0"),
17+
.package(url: "https://github.com/Quick/Nimble.git", from: "9.2.0"),
18+
19+
],
20+
targets: [
21+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
22+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
23+
.target(
24+
name: "Json",
25+
dependencies: [
26+
27+
]),
28+
.testTarget(
29+
name: "JsonTests",
30+
dependencies: ["Json", "Quick", "Nimble"]),
31+
]
32+
)

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Json
2+
3+
A description of this package.
4+
```swift
5+
let json = "".toJson()
6+
let json = data.toJson()
7+
let json = dictionary.toJson()
8+
let json = model.toJson()
9+
```
10+
11+
```swift
12+
let data = json.toData()
13+
let string = json.toString()
14+
let dictionary = json.toDictionary()
15+
let model = json.toModel(Model.self)
16+
```

Sources/Json/ExtensionJson+.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Foundation
2+
3+
4+
public extension String {
5+
6+
func toJson() -> Json {
7+
Json(parseJson: self)
8+
}
9+
10+
}
11+
12+
public extension Data {
13+
func toJson() -> Json {
14+
Json(data: toDataPrettyPrinted())
15+
}
16+
}
17+
18+
public extension Dictionary {
19+
func toJson()-> Json {
20+
Json(self)
21+
}
22+
}
23+
24+
public extension Encodable {
25+
26+
func toJson() -> Json {
27+
Json(toData() as Any)
28+
}
29+
30+
}

0 commit comments

Comments
 (0)