You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-19Lines changed: 59 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,9 @@ After developing a number of applications, we noticed that everyone's networking
8
8
### Dependencies
9
9
------
10
10
11
-
We ended up going with [Alamofire](https://github.com/Alamofire/Alamofire) instead of `URLSession` for a few reasons. Alamofire is asynchronous by nature, has session management, reduces boilerplate code, and is very easy to use.
11
+
*[Alamofire](https://github.com/Alamofire/Alamofire) - We ended up going with Alamofire instead of `URLSession` for a few reasons. Alamofire is asynchronous by nature, has session management, reduces boilerplate code, and is very easy to use.
12
+
13
+
*[PromiseKit](https://github.com/mxcl/PromiseKit) - We use Promises because they simplify asynchronous programming and separate successful and failed responses, allowing you to focus on each part in their own individual closures.
1. Run `carthage update --platform iOS --no-use-binaries` to build the framework.
36
-
1. On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop `BuckoNetworking.framework` from the [Carthage/Build]() folder on disk. You will also need to drag `Alamofire.framework` into your project.
38
+
1. On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop `BuckoNetworking.framework` from the [Carthage/Build]() folder on disk. You will also need to drag `Alamofire.framework`and `PromiseKit.framework`into your project.
37
39
1. On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script in which you specify your shell (ex: `/bin/sh`), add the following contents to the script area below the shell:
This script works around an [App Store submission bug](http://www.openradar.me/radar?id=6409498411401216) triggered by universal binaries and ensures that necessary bitcode-related files and dSYMs are copied when archiving.
50
53
@@ -91,10 +94,7 @@ $ pod install
91
94
92
95
Swift 4 introduced the Codable protocol and the `DecodableEndpoint` in BuckoNetworking uses this to the max!
93
96
94
-
95
97
```swift
96
-
importBuckoNetworking
97
-
98
98
structUser: Decodable {
99
99
var name: String
100
100
var phoneNumber: String
@@ -107,17 +107,29 @@ struct User: Decodable {
107
107
108
108
structUserService: DecodableEndpoint {
109
109
typealiasResponseType= User
110
-
var baseURL: String="https://example.com/"
111
-
var path: String="users/"
112
-
var method: HTTPMethod = .post
113
-
var parameters: Parameters {
114
-
var parameters =Parameters()
115
-
parameters["first_name"] ="Bucko"
116
-
return parameters
110
+
var baseURL: String { return"https://example.com" }
111
+
var path: String { return"/users" }
112
+
var method: HTTPMethod { return .get }
113
+
var body: Parameters { returnParameters() }
114
+
var headers: HTTPHeaders { returnHTTPHeaders() }
115
+
}
116
+
117
+
UserService().request().then { users in
118
+
// Do something with users
119
+
users.count
120
+
}.catch { error in
121
+
122
+
iflet json = error.json {
123
+
// Use json
124
+
} else {
125
+
// Some other error occurred that doesn't include json
117
126
}
118
-
var headers: HttpHeaders = ["Authorization":"Bearer SOME_TOKEN"]
119
127
}
128
+
```
129
+
130
+
If you don't want to use Promises, BuckoNetworking also provides normal closures:
120
131
132
+
```swift
121
133
UserService().request { (user, error) in
122
134
guardlet user = user else {
123
135
// Do Error
@@ -143,6 +155,20 @@ enum UserService: Endpoint {
143
155
var headers: HTTPHeaders { returnHTTPHeaders() }
144
156
}
145
157
158
+
// Use your Endpoint
159
+
UserService.index.request(responseType: [User].self).then { users in
160
+
// Do something with users
161
+
users.count
162
+
}.catch { error in
163
+
164
+
iflet json = error.json {
165
+
// Use json
166
+
} else {
167
+
// Some other error occurred that doesn't include json
168
+
}
169
+
}
170
+
171
+
// Or without Promises
146
172
UserService.index.request(responseType: [User].self) { (users, error) in
147
173
guardlet users = users else {
148
174
// Do Error
@@ -163,7 +189,7 @@ If you don't want to use `Codable`, you can instead use the `Endpoint` protocol,
0 commit comments