소스 검색

Added value and error computed properties to data and download responses.

Christian Noon 9 년 전
부모
커밋
8525217ec3
1개의 변경된 파일12개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      Source/Response.swift

+ 12 - 0
Source/Response.swift

@@ -87,6 +87,12 @@ public struct DataResponse<Value> {
     /// The timeline of the complete lifecycle of the request.
     public let timeline: Timeline
 
+    /// Returns the associated value of the result if it is a success, `nil` otherwise.
+    public var value: Value? { return result.value }
+
+    /// Returns the associated error value if the result if it is a failure, `nil` otherwise.
+    public var error: Error? { return result.error }
+
     var _metrics: AnyObject?
 
     /// Creates a `DataResponse` instance with the specified parameters derived from response serialization.
@@ -220,6 +226,12 @@ public struct DownloadResponse<Value> {
     /// The timeline of the complete lifecycle of the request.
     public let timeline: Timeline
 
+    /// Returns the associated value of the result if it is a success, `nil` otherwise.
+    public var value: Value? { return result.value }
+
+    /// Returns the associated error value if the result if it is a failure, `nil` otherwise.
+    public var error: Error? { return result.error }
+
     var _metrics: AnyObject?
 
     /// Creates a `DownloadResponse` instance with the specified parameters derived from response serialization.