TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | May 2016 |
SPMSupports SPM | ✓ |
Maintained by Rahul Katariya.
Restofire-Gloss is a component library for Restofire to serialize responses into Gloss
To use Restofire as a Swift Package Manager package just add the following in your Package.swift file.
import PackageDescription
let package = Package(
name: "HelloRestofireGloss",
dependencies: [
.Package(url: "https://github.com/Restofire/Restofire-Gloss.git", majorVersion: 1)
]
)
import Restofire
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
Restofire.defaultConfiguration.baseURL = "http://www.mocky.io/v2/"
Restofire.defaultConfiguration.headers = ["Content-Type": "application/json"]
Restofire.defaultConfiguration.logging = true
Restofire.defaultConfiguration.authentication.credential = NSURLCredential(user: "user", password: "password", persistence: .ForSession)
Restofire.defaultConfiguration.validation.acceptableStatusCodes = [200..<300]
Restofire.defaultConfiguration.validation.acceptableContentTypes = ["application/json"]
Restofire.defaultConfiguration.retry.retryErrorCodes = [NSURLErrorTimedOut,NSURLErrorNetworkConnectionLost]
Restofire.defaultConfiguration.retry.retryInterval = 20
Restofire.defaultConfiguration.retry.maxRetryAttempts = 10
let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
sessionConfiguration.timeoutIntervalForRequest = 7
sessionConfiguration.timeoutIntervalForResource = 7
sessionConfiguration.HTTPAdditionalHeaders = Manager.defaultHTTPHeaders
Restofire.defaultConfiguration.manager = Alamofire.Manager(configuration: sessionConfiguration)
return true
}
}
import Gloss
struct Person: Decodable {
var id: Int
var name: String
init(id: Int, name: String) {
self.id = id
self.name = name
}
init?(json: JSON) {
guard let id: Int = "id" <~~ json,
let name: String = "name" <~~ json else { return nil }
self.id = id
self.name = name
}
}
extension Person: Equatable { }
func ==(lhs: Person, rhs: Person) -> Bool {
return lhs.id == rhs.id && lhs.name == rhs.name
}
import Restofire
class PersonGETService: Requestable {
typealias Model = Person
var path: String = "56c2cc70120000c12673f1b5"
}
import Restofire
class ViewController: UIViewController {
var person: Person!
var requestOp: RequestOperation!
func getPerson() {
requestOp = PersonGETService().executeTask() {
if let value = $0.result.value {
person = value
}
}
}
deinit {
requestOp.cancel()
}
}
Restofire is released under the MIT license. See LICENSE for details.