Skip to content

ye7ia33/Alamofire-With-Codable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Alamofire-With-Codable

using Alamofire 4 With Codable

  • init pod
  • then add cocopoads repositry
    1. pod 'Alamofire', '~> 4.7'
    2. pod 'SwiftyJSON', '~> 4.2'
  • installing pods 3- then drag and two files into project

then if you need to calling

  • Example to use
  • Create contact model
  • Inject phone model into Contact class
    struct Contact: Codable {
        var id : String
        var name : String
        var email : String
        var address : String
        var gender : String
        var phone : Phone
    }

    struct Phone: Codable {
        var mobile : String
        var home : String
        var office : String
    }


    import SwiftyJSON

    class ViewController: UIViewController {

    
    var contactArray = [Contact]()
    override func viewDidLoad() {
        super.viewDidLoad()
     
        AF.request(request_url: "http://www.mocky.io/v2/5c5af29d3200007b274ec88a") {
            (result , erroCode, errorMessage) in
            
            let responseObject = JSON(result ?? "")
            let contactJsonArray =  responseObject["contacts"]
            for aContact in contactJsonArray{

                let contactModel =  CodableJson.decode(Contact.self, from:aContact.1)
              
                if contactModel != nil { self.contactArray.append(contactModel as! Contact) }
             }

            print(self.contactArray)
        }
    }
    
    }

About

using Alamofire 4 With Codable

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages