Skip to content

Commit a606a28

Browse files
committed
Merge pull request #158 from ishkawa/feature/class-shared-session
Change sharedSession and related methods from `static` to `class`
2 parents 8bc28b2 + f839ebb commit a606a28

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Sources/Session.swift

+9-5
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,22 @@ public class Session {
7171
}
7272
}
7373

74-
// Shared session for static methods
75-
public static let sharedSession = Session(URLSession: NSURLSession(
74+
// Shared session for class methods
75+
private static let privateSharedSession = Session(URLSession: NSURLSession(
7676
configuration: NSURLSessionConfiguration.defaultSessionConfiguration(),
7777
delegate: URLSessionDelegate(),
7878
delegateQueue: nil
7979
))
80-
81-
public static func sendRequest<T: RequestType>(request: T, handler: (Result<T.Response, APIError>) -> Void = {r in}) -> NSURLSessionDataTask? {
80+
81+
public class var sharedSession: Session {
82+
return privateSharedSession
83+
}
84+
85+
public class func sendRequest<T: RequestType>(request: T, handler: (Result<T.Response, APIError>) -> Void = {r in}) -> NSURLSessionDataTask? {
8286
return sharedSession.sendRequest(request, handler: handler)
8387
}
8488

85-
public static func cancelRequest<T: RequestType>(requestType: T.Type, passingTest test: T -> Bool = { r in true }) {
89+
public class func cancelRequest<T: RequestType>(requestType: T.Type, passingTest test: T -> Bool = { r in true }) {
8690
sharedSession.cancelRequest(requestType, passingTest: test)
8791
}
8892
}

0 commit comments

Comments
 (0)