Skip to content

Commit e012698

Browse files
committed
Add Unbox and reorganize
1 parent e2e353f commit e012698

Some content is hidden

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

54 files changed

+5555
-2072
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ script:
2626
- xcodebuild -workspace Example/APIKitExt.xcworkspace -scheme "Himotoki Sample" CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" | xcpretty -c
2727
- xcodebuild -workspace Example/APIKitExt.xcworkspace -scheme "ModelMapper Sample" CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" | xcpretty -c
2828
- xcodebuild -workspace Example/APIKitExt.xcworkspace -scheme "JASON Sample" CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" | xcpretty -c
29+
- xcodebuild -workspace Example/APIKitExt.xcworkspace -scheme "Unbox Sample" CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" | xcpretty -c
2930
- xcodebuild build-for-testing test-without-building -workspace Example/APIKitExt.xcworkspace -scheme "Himotoki Sample Tests" -destination 'name=iPhone 7' | xcpretty -c

APIKitExt.podspec

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ APIKitExt is a set of useful extension to work with APIKit and libraries such as
5757
ss.dependency "JASON", '3.1'
5858
end
5959

60+
s.subspec "Unbox" do |ss|
61+
ss.source_files = "Sources/Classes/Unbox/*.swift"
62+
ss.dependency "APIKitExt/Core"
63+
ss.dependency "Unbox", '2.3.0'
64+
end
65+
6066
s.subspec "RxSwift" do |ss|
6167
ss.source_files = "Sources/Classes/RxSwift/*.swift"
6268
ss.dependency "APIKitExt/Core"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Documentations/UnboxUsage.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## How to use APIKit + Unbox
2+
Example using APIKitExt to combine APIKit and Unbox.
3+
Note that a complete example is available at [Unbox Sample folder](https://github.com/DTVD/APIKitExt/tree/master/Example/Unbox%20Sample).
4+
5+
### Model (Unbox)
6+
Our model file will follow normal Unbox's guide.
7+
```swift
8+
struct Repo {
9+
var id: Int
10+
var fullName: String
11+
var stargazersCount: Int
12+
}
13+
14+
extension Repo: Unboxable {
15+
init(unboxer: Unboxer) throws {
16+
id = try unboxer.unbox(key: "id")
17+
fullName = try unboxer.unbox(key: "full_name")
18+
stargazersCount = try unboxer.unbox(key: "stargazers_count")
19+
}
20+
}
21+
```
22+
23+
### Defining request type (APIKit + APIKitExt)
24+
With APIKit used along with APIKitExt, we can parse Json result and immediately return Response type :tada:
25+
```swift
26+
struct RepoRequest: Request {
27+
typealias Response = [Repo]
28+
// ...
29+
}
30+
31+
extension RepoRequest {
32+
func response(from object: Any, urlResponse: HTTPURLResponse) -> [Repo] {
33+
guard
34+
let tree = object as? [String: Any],
35+
let items = tree["items"],
36+
let repos = try? Repo.mapArray(items) // <- notice mapArray method here !
37+
else {
38+
return []
39+
}
40+
return repos
41+
}
42+
}
43+
```
44+
45+
### Supported method
46+
Here is list of supported methods
47+
* `mapObject` : map a json object to a model object.
48+
* `mapArray` : map a json object to a list of model objects.

Example/APIKitExt.xcodeproj/project.pbxproj

Lines changed: 235 additions & 58 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)