Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Otbivnoe committed Jun 11, 2017
1 parent 9dac507 commit 13d81cc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
14 changes: 10 additions & 4 deletions CodableAlamofire.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
84A8C8511EED2F2700AB31BE /* CodableAlamofire.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8C84D1EED2F0C00AB31BE /* CodableAlamofire.h */; settings = {ATTRIBUTES = (Public, ); }; };
84A8C8521EED2F2800AB31BE /* CodableAlamofire.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8C84D1EED2F0C00AB31BE /* CodableAlamofire.h */; settings = {ATTRIBUTES = (Public, ); }; };
84A8C8531EED2F2800AB31BE /* CodableAlamofire.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8C84D1EED2F0C00AB31BE /* CodableAlamofire.h */; settings = {ATTRIBUTES = (Public, ); }; };
84D535E31EED5A5E00B6CB47 /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D535E21EED5A5E00B6CB47 /* Errors.swift */; };
84D535E31EED5A5E00B6CB47 /* AlamofireDecodableError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D535E21EED5A5E00B6CB47 /* AlamofireDecodableError.swift */; };
84D535E41EED5DD500B6CB47 /* MainTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D535E11EED590900B6CB47 /* MainTests.swift */; };
84D535E51EED5DD500B6CB47 /* MainTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D535E11EED590900B6CB47 /* MainTests.swift */; };
84D535E61EED5DD500B6CB47 /* MainTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D535E11EED590900B6CB47 /* MainTests.swift */; };
84D535E71EED645000B6CB47 /* AlamofireDecodableError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D535E21EED5A5E00B6CB47 /* AlamofireDecodableError.swift */; };
84D535E81EED645000B6CB47 /* AlamofireDecodableError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D535E21EED5A5E00B6CB47 /* AlamofireDecodableError.swift */; };
84D535E91EED645100B6CB47 /* AlamofireDecodableError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D535E21EED5A5E00B6CB47 /* AlamofireDecodableError.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -120,7 +123,7 @@
84A8C84D1EED2F0C00AB31BE /* CodableAlamofire.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CodableAlamofire.h; sourceTree = "<group>"; };
84A8C84E1EED2F0C00AB31BE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
84D535E11EED590900B6CB47 /* MainTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTests.swift; sourceTree = "<group>"; };
84D535E21EED5A5E00B6CB47 /* Errors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = "<group>"; };
84D535E21EED5A5E00B6CB47 /* AlamofireDecodableError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlamofireDecodableError.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -247,7 +250,7 @@
isa = PBXGroup;
children = (
8472D2D91EED3BE500E81232 /* DataRequest+Decodable.swift */,
84D535E21EED5A5E00B6CB47 /* Errors.swift */,
84D535E21EED5A5E00B6CB47 /* AlamofireDecodableError.swift */,
84A8C84C1EED2F0C00AB31BE /* Supporting Files */,
);
path = Sources;
Expand Down Expand Up @@ -636,7 +639,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
84D535E31EED5A5E00B6CB47 /* Errors.swift in Sources */,
84D535E31EED5A5E00B6CB47 /* AlamofireDecodableError.swift in Sources */,
8472D2DD1EED3BF200E81232 /* DataRequest+Decodable.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -646,6 +649,7 @@
buildActionMask = 2147483647;
files = (
8472D2DA1EED3BF100E81232 /* DataRequest+Decodable.swift in Sources */,
84D535E71EED645000B6CB47 /* AlamofireDecodableError.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -654,6 +658,7 @@
buildActionMask = 2147483647;
files = (
8472D2DC1EED3BF200E81232 /* DataRequest+Decodable.swift in Sources */,
84D535E81EED645000B6CB47 /* AlamofireDecodableError.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -662,6 +667,7 @@
buildActionMask = 2147483647;
files = (
8472D2DB1EED3BF100E81232 /* DataRequest+Decodable.swift in Sources */,
84D535E91EED645100B6CB47 /* AlamofireDecodableError.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
11 changes: 8 additions & 3 deletions Sources/Errors.swift → Sources/AlamofireDecodableError.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
//
// Errors.swift
// CodableAlamofire-iOS
// AlamofireDecodableError.swift
// CodableAlamofire
//
// Created by Nikita Ermolenko on 11/06/2017.
//

import Foundation

/// `AlamofireDecodableError` is the error type returned by CodableAlamofire.
///
/// - invalidKeyPath: Returned when a nested dictionary object doesn't exist by special keyPath.
/// - emptyKeyPath: Returned when a keyPath is empty.

public enum AlamofireDecodableError: Error {
case invalidKeyPath
case emptyKeyPath
Expand All @@ -16,7 +21,7 @@ extension AlamofireDecodableError: LocalizedError {

public var errorDescription: String? {
switch self {
case .invalidKeyPath: return "Nested object doesn't exist by this KeyPath."
case .invalidKeyPath: return "Nested object doesn't exist by this keyPath."
case .emptyKeyPath: return "KeyPath can not be empty."
}
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/DataRequest+Decodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ extension DataRequest {
}
}


/// Adds a handler to be called once the request has finished.

/// - parameter queue: The queue on which the completion handler is dispatched.
/// - parameter keyPath: The keyPath where object decoding should be performed. Default: `nil`.
/// - parameter decoder: The decoder that performs the decoding of JSON into semantic `Decodable` type. Default: `JSONDecoder()`.
/// - parameter completionHandler: The code to be executed once the request has finished and the data has been mapped by `JSONDecoder`.

/// - returns: The request.

@discardableResult
public func responseDecodableObject<T: Decodable>(queue: DispatchQueue? = nil, keyPath: String? = nil, decoder: JSONDecoder = JSONDecoder(), completionHandler: @escaping (DataResponse<T>) -> Void) -> Self {
return response(queue: queue, responseSerializer: DataRequest.DecodableObjectSerializer(keyPath, decoder), completionHandler: completionHandler)
Expand Down

0 comments on commit 13d81cc

Please sign in to comment.