Int
- Double
- Float
- Data
to String
eg: SomeData.stringValue
UIImage
: averageColor: UIColor?
& resizeImage(targetSize: CGSize) -> UIImage
UIImageView
: setImageColor(color: UIColor)
UILabel
: calculateMaxLines() -> Int
UIView
: Auto loadable from xibFlexible, cancellable, error safe
import YNetworkKit
ApiConstant.apiDefault.set(defaultDomain: "https://api.mocki.io")
class Interactor: Networkable {
var someDataRequests: BaseRequestModel?
func getSomeData(result: @escaping (Result<TestResponse, Error>) -> Void) {
someDataRequests = BaseRequestModel(path: "/v1/d0e7928e", method: .GET([]))
guard let someDataRequests = someDataRequests else { return }
send(requestData: someDataRequests, modelType: TestResponse.self, result: result)
}
func cancel() {
someDataRequests?.cancel()
}
}
public protocol Networkable {
func send<T>(requestData: BaseRequestProtocol,
modelType: T.Type,
decoder: JSONDecoder,
urlSession: NetworkProtocol,
result: @escaping (Result<T, Error>) -> Void) where T : Decodable
}
When you used MockURLSession, json file from url last path and uses
public class MockURLSession: NetworkProtocol {
let bundle: Bundle
/// MockURLSession: Request handle json file content
/// - Parameter bundle: Your json file bundle
public init(bundle: Bundle) {
self.bundle = bundle
}
public func dataTaskPublisher(for request: URLRequest) -> URLSession.DataTaskPublisher {
let stubReply = request.url?.lastPathComponent ?? "stub_error"
return URLSession.shared.dataTaskPublisher(for: bundle.url(forResource: stubReply, withExtension: "json")!)
}
}
// Send Request with mock URLSession
send(requestData: someDataRequests,
modelType: TestResponse.self,
urlSession: MockURLSession.init(bundle: Bundle(for: type(of: self))),
result: result)
link |
Stars: 0 |
Last commit: 2 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics