Latest 5.0.2
Homepage https://github.com/JuanjoArreola/Apic
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0, requires ARC
Dependencies AsyncRequest
Authors

Cocoapods
Platform
License
codebeat badge

Apic communicates with RESTful services, parses the JSON HTTP response and delivers objects.

Installation

CocoaPods

Swift < 2.3:

pod ‘Apic’ ‘~> 2.2.4’

Swift 3.x :

pod ‘Apic’ ‘~> 3.9.6’

Swift 4

pod ‘Apic’ ‘~> 4.0.0’
pod ‘Apic’ ‘~> 5.0.0’

Repositories

The repository is a class that implements the logic to communicate with the services that provide the REST resources, basically a Repository has methods that correspond to endpoints in the backend, all repositories inherit from the generic class AbstractRepository:

class GistsRepository: AbstractRepository {
    func requestGistsOfUser(_ user: String, completion: ([Gist]) -> Void) -> Request<[Gist]> {
        return requestArray(route: .get("https://api.github.com/users/(user)/gists"), completion: completion)
    }
}

The only requirement is that Gist implements Decodable

This repository can now be used by a ViewController to request a user’s gists.

class GistsController: UITableViewController {

    let gistsRepository = GistsRepository()
    var gists: [Gist]?
    var gistsRequest: Request<[Gist]>?

    override func viewDidLoad() {
        super.viewDidLoad()
        requestGists()
    }

    func requestGists() {
        gistsRequest?.cancel()
        gistsRequest = gistsRepository.requestGistsOfUser("UserName", completion: { [weak self] gists in
            self?.gists = gists
        }).fail { [weak self] error in
            self?.handleError(error)
        }.finished { [weak self] in
            self?.tableView.reloadData()
        }
    }
}

When the GistsRepository finishes calling the service and parsing the response it calls the completion closure that you provide sending you an array of [Gist] in this case.

Latest podspec

{
    "name": "Apic",
    "version": "5.0.2",
    "summary": "Apic is a library that parses JSON API responses into swift objects",
    "homepage": "https://github.com/JuanjoArreola/Apic",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Juanjo Arreola": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/JuanjoArreola/Apic.git",
        "tag": "5.0.2"
    },
    "source_files": "Sources/*.swift",
    "requires_arc": true,
    "ios": {
        "frameworks": "SystemConfiguration"
    },
    "osx": {
        "frameworks": "SystemConfiguration"
    },
    "tvos": {
        "frameworks": "SystemConfiguration"
    },
    "dependencies": {
        "AsyncRequest": [
            "~> 2.1.0"
        ]
    },
    "swift_version": "4.1"
}

Pin It on Pinterest

Share This