1

I made swift app and i will use Alamofire for swift json parsing.

For that i install following pod:

pod 'Alamofire', '~> 4.4'

After that i update pod but it will give me following error :

[!] CocoaPods was not able to update the master repo. If this is an unexpected issue and persists you can inspect it running pod repo update --verbose

so any one have solution of that then please help me.

I used xcode 8.3.1 ,Swift 3 and app compatibility from ios 9.0.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

0

This answer could fix your problem:

Uninstall CocoaPods (choose to uninstall all versions):

sudo gem uninstall cocoapods

Remove old master repo:

sudo rm -fr ~/.cocoapods/repos/master

Install CocoaPods without sudo:

gem install --user-install cocoapods

Setup CocoaPods and Master repo:

pod setup

NOTE: Step 3 is going to make sure you install pod under your user name instead of root which sudo does.

MGY
  • 7,245
  • 5
  • 41
  • 74
0

For iOS Swift 4 :

go through this link :

http://ashishkakkad.com/2015/10/how-to-use-alamofire-and-swiftyjson-with-swift/

step 1 - install pod

pod 'Alamofire'

step 2 - import Alamofire (in your VC)

step 3 - create URL & parameters for that

let params:[String:String] = ["Name":self.name]
or
let params = nil

step 4 - call the func

public func GET_ALL(params:[String:String])
    
{
    let baseURL = "your url"
    
    if NetworkReachabilityManager()?.isReachable == true
    {
        AppDelegate.sharedInstance().ShowSpinnerView()
        Alamofire.request(baseURL, method: .post, parameters: params, encoding: JSONEncoding.default, headers: nil).response { (response) in
            AppDelegate.sharedInstance().HideSpinnerView()
            do
            {
                let dict = try? JSONSerialization.jsonObject(with: response.data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSMutableDictionary
                if dict?.count==0 || dict == nil
                {
                    let alert = UIAlertController(title: APPNAME, message: "No reposnse from server.", preferredStyle: .alert)
                    let action = UIAlertAction(title: "OK", style: .default, handler: { (action) in
                        
                    })
                    
                    alert.addAction(action)
                    self.present(alert, animated: true, completion: nil)
                }
                else
                {
                    self.checkDictionary(dict!)
                    if dict?.object(forKey: "data") is NSMutableDictionary
                    {
                        
                        self.arrAllData = (dict?.value(forKeyPath: "data.myName") as? NSMutableArray)!
                        
                        if(self.arrAllData.count == 0)
                        {
                          
                        }
                        else
                        {
                           
                        }
                        self.TableView.reloadData()
                    }
                    else
                    {
                        
                    }
                }
            }
            catch let error as NSError
            {
                print(error.localizedDescription)
                let alert = UIAlertController(title: APPNAME, message: error.localizedDescription, preferredStyle: .alert)
                let action = UIAlertAction(title: "OK", style: .default)
                { (action) in
                }
                
                alert.addAction(action)
                self.present(alert, animated: true, completion: nil)
                self.hideSpinner()
            }
        }
    }
    else
    {
        AppDelegate.sharedInstance().HideSpinnerView()
        let alert = UIAlertController(title: APPNAME, message: "No network available.", preferredStyle: .alert)
        let action = UIAlertAction(title: "OK", style: .default)
        { (action) in
        }
        alert.addAction(action)
        self.present(alert, animated: true, completion: nil)
    }
}

let params:[String:String] = ["slug":self.strSlug]

let header = ["Content-Type":"application/x-www-form-urlencoded", "Authorization": "Basic aW50cmFpZXAwMDE6dWZaeWFyUlp3NE1CeUg4RA==" ]

let url = API.GET_NEWS

**Info.plis : make sure you have added -> App transport Security Setting : Allow Arbitrary Loads : YES **

 self.ArrData = dict?.value(forKeyPath: "results") as? NSMutableArray
                        
                        for i in 0...self.ArrData.count-1{
                        
                            let dict = self.ArrData[i] as? NSMutableDictionary
                            let dictGeometry = dict?.value(forKeyPath: "geometry") as? NSMutableDictionary
                            
                            let TempDict = NSMutableDictionary()
                            TempDict.setObject(String(dictGeometry?.value(forKeyPath: "location.lat") as? Double ?? 0.0), forKey: "lat" as NSCopying)
                            TempDict.setObject(String(dictGeometry?.value(forKeyPath: "location.lng") as? Double ?? 0.0), forKey: "lng" as NSCopying)
                            TempDict.setObject(dict?.value(forKeyPath: "icon") as? String ?? "", forKey: "icon" as NSCopying)
                            TempDict.setObject(dict?.value(forKeyPath: "name") as? String ?? "", forKey: "name" as NSCopying)
                            TempDict.setObject(dict?.value(forKeyPath: "vicinity") as? String ?? "", forKey: "vicinity" as NSCopying)
                            
                            print(TempDict)
                            self.ArrFinalData.add(TempDict)
                            
                        }
                        
                        print(self.ArrFinalData.count)

Swift Alamofire Method Calling:

func getMovieList(page: Int){
    
    let url = API.SERVER_URL + "\(page)"
    Alamofire.request(URL(string: url)!, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { (responseObject) in
        let response = self.formatResponse(data: responseObject)
        let arr = response["results"] as! [[String : AnyObject]]
        self.arrMovie.append(contentsOf: arr)
        self.MoviewList = MovieDataList(data: self.arrMovie)
        self.tableView.reloadData()
        self.isLoadingList = false
        self.deleteAllRecords()
    }
}

func formatResponse(data:DataResponse<Any>)-> [String:AnyObject]
{
    let responseObject = data.result.value as? [NSObject: AnyObject]
    let response = responseObject as? [String : AnyObject]
    return response ?? [:]
}

github.com/tej1107/MVC_MOVIEDEMO github.com/tej1107/TableView_CollectionView github.com/tej1107/TableView_CollectionView github.com/tej11695/MVC_UserList github.com/tej11695/New_MVC github.com/tej11695/EmployeeRegistration github.com/tej11695/List-SignUp_API

pod 'SDWebImage' pod 'Alamofire','4.9.1'

Tej Patel
  • 119
  • 2
  • 5