Skip to content

Commit

Permalink
Json
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenPhongVN committed Jan 22, 2022
0 parents commit b45da43
Show file tree
Hide file tree
Showing 11 changed files with 1,269 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"object": {
"pins": [
{
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "682841464136f8c66e04afe5dbd01ab51a3a56f2",
"version": "2.1.0"
}
},
{
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "0630439888c94657a235ffcd5977d6047ef3c87b",
"version": "2.0.1"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "c93f16c25af5770f0d3e6af27c9634640946b068",
"version": "9.2.1"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "bd86ca0141e3cfb333546de5a11ede63f0c4a0e6",
"version": "4.0.0"
}
}
]
},
"version": 1
}
32 changes: 32 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Json",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Json",
targets: ["Json"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/Quick/Quick.git", from: "4.0.0"),
.package(url: "https://github.com/Quick/Nimble.git", from: "9.2.0"),

],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Json",
dependencies: [

]),
.testTarget(
name: "JsonTests",
dependencies: ["Json", "Quick", "Nimble"]),
]
)
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Json

A description of this package.
```swift
let json = "".toJson()
let json = data.toJson()
let json = dictionary.toJson()
let json = model.toJson()
```

```swift
let data = json.toData()
let string = json.toString()
let dictionary = json.toDictionary()
let model = json.toModel(Model.self)
```
30 changes: 30 additions & 0 deletions Sources/Json/ExtensionJson+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation


public extension String {

func toJson() -> Json {
Json(parseJson: self)
}

}

public extension Data {
func toJson() -> Json {
Json(data: toDataPrettyPrinted())
}
}

public extension Dictionary {
func toJson()-> Json {
Json(self)
}
}

public extension Encodable {

func toJson() -> Json {
Json(toData() as Any)
}

}
Loading

0 comments on commit b45da43

Please sign in to comment.