📬 A pure Swift implementation of some services for brazilian state post office: Correios.
To run the example project, clone the repo, and run pod install
from the Example directory first.
- Swift 4 or higher
Request information about an address based on the given cep.
...
override func viewDidLoad() {
super.viewDidLoad()
Cocoarreios.request(.address(cep: "01001000")) { result in
switch result {
case .success(let address):
print(address.cep) // => "01001-000"
print(address.publicPlace) // => "Praça da Sé"
print(address.complement) // => "lado Ãmpar"
print(address.neighborhood) // => "Sé"
print(address.city) // => "São Paulo"
print(address.state) // => "SP"
print(address.unity) // => ""
print(address.ibge) // => "3550308"
print(address.gia) // => "1004"
case .failure(let error):
//Do something with error...
}
}
}
...
It's also possible to use the delegate pattern.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let cocoarreios = Cocoarreios()
cocoarreios.delegate = self
cocoarreios.request(.address(cep: "01001000"))
}
}
extension ViewController: CocoarreiosDelegate {
func receivedAddress(with result: Result<Address, MoyaError>) {
switch result {
case .success(let address):
// Use address here...
case .failure(let error):
// Do something with error
}
}
}
Cocoarreios is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Cocoarreios'
pogist, murilo.paixao.2@gmail.com
Cocoarreios is available under the MIT license. See the LICENSE file for more info.