Skip to content

About SwiftlyNetworker is very Ez Netwoker!! πŸ§‘β€πŸ’»

License

Notifications You must be signed in to change notification settings

jungseungyeo/SwiftlyNetworker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SwiftlyNetworker

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

SwiftlyNetworker is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SwiftlyNetworker'

How to use

enum SojuAPI {
    case list
}

extension SojuAPI: APIable {
    var params: [String : Any]? {
        nil
    }

    var path: String {
        "/TestJSONfile/main/JSON/Test.json"
    }

    var method: HttpMethod {
        .get
    }

    var log: Bool { return false }
}
import SwiftlyNetworker

// ViewModel
class ViewModel {

    init(
        networker: NetworkerLogic = SwiftlyNetworker(componet: NetworkerLogicDependency)
    ) {
        self.networker = networker
    }

    func request() -> AnyPublisher<Model, Error> {
        return networker.request(SojuAPI.list).eraseToAnyPublisher()
    }

    func request(complete: @escaping ((Result<Model, Error>) -> Void)) {
        networker.request(SojuAPI.list, complete: complete)
    }
}


// UIViewController
class ViewController: UIViewController {

    private let viewModel = ViewModel()

    override func viewDidLoad() {
        super.viewDidLoad()

        // MARK: - Combine
        viewModel.request()
            .sink { completion in
                switch completion {
                case .finished:
                    print("finish")
                case .failure(let error):
                    print("error: \(error.localizedDescription)")
                }
            } receiveValue: { (model: Model) in
                print("model \(model)")
            }.store(in: &cancellables)


        // MARK: - Closure
        viewModel.request { (result: Result<Model, Error>) in
            switch result {
            case .success(let model):
                print("model \(model)")
            case .failure(let error):
                print("error: \(error.localizedDescription)")
            }
        }
    }
}

Author

linsaeng, [email protected]

License

SwiftlyNetworker is available under the MIT license. See the LICENSE file for more info.

About

About SwiftlyNetworker is very Ez Netwoker!! πŸ§‘β€πŸ’»

Resources

License

Stars

Watchers

Forks

Packages

No packages published