-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseModel.swift
49 lines (35 loc) · 1.26 KB
/
BaseModel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// BaseModel.swift
// Gank
//
// Created by 魏星 on 16/7/17.
// Copyright © 2016年 wx. All rights reserved.
//
import Foundation
import Moya
import RxSwift
import ObjectMapper
class BaseModel<T:TargetType>{
var requestProvider: RxMoyaProvider<T>
var page = 1
var offset = 20
var backgroundScheduler: OperationQueueScheduler!
init(){
let operationQueue = NSOperationQueue()
operationQueue.maxConcurrentOperationCount = 3
operationQueue.qualityOfService = .UserInitiated
backgroundScheduler = OperationQueueScheduler(operationQueue: operationQueue)
let networkActivityPlugin = NetworkActivityPlugin { (change) in
switch(change){
case .Began:
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
case .Ended:
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}
}
self.requestProvider = RxMoyaProvider<T>(plugins: [networkActivityPlugin,NetworkLoggerPlugin.init()])
}
func parseObject<T: Mappable>(response: Response) throws -> T {
return try Mapper<T>().map(response.mapString())!
}
}