我制作了一个快速的应用程序,我将使用Alamofire进行快速的json解析。
为此,我安装了以下pod:
荚‘阿拉莫火’,'~> 4.4'
在此之后,我更新了pod,但是它会给我以下错误:
!master CocoaPods无法更新回购。如果这是一个意外的问题,并且持久化,您可以检查它运行
所以任何一个人都有解决办法,那就请帮帮我。
我使用了xcode 8.3.1、Swift 3和ios 9.0中的应用程序兼容性。
发布于 2017-05-31 13:23:26
This answer可以解决您的问题:
卸载CocoaPods (选择卸载所有版本):
sudo gem uninstall cocoapods移除旧的主回购:
sudo rm -fr ~/.cocoapods/repos/master安装没有sudo的CocoaPods:
gem install --user-install cocoapods安装CocoaPods和主回购:
pod setup注意:步骤3将确保您在用户名下安装pod,而不是根用户,sudo这样做。
发布于 2019-03-11 06:46:17
For iOS Swift 4 :
通过这个链接:
http://ashishkakkad.com/2015/10/how-to-use-alamofire-and-swiftyjson-with-swift/步骤1-安装吊舱
pod 'Alamofire'步骤2-导入阿拉莫火(在您的VC中)
步骤3-为此创建URL和参数
let params:[String:String] = ["Name":self.name]
or
let params = nil步骤4-调用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)
}
}让params:String:String =“String”:self.strSlug let头= "Content-Type":"application/x-www-form-urlencoded",“aW50cmFpZXAwMDE6dWZaeWFyUlp3NE1CeUg4RA==”:"Basic aW50cmFpZXAwMDE6dWZaeWFyUlp3NE1CeUg4RA==“let url = API.GET_NEWS **Info.plis :确保您添加了->应用程序传输安全设置:允许任意加载:是**
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)快速Alamofire方法调用:
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/New 1107/MVC_MOVIEDEMO github.com/New 1107/TableView_CollectionView github.com/New 1107/TableView_CollectionView github.com/New 11695/MVC_UserList github.com/tej11695/New_MVC github.com/List 11695/EmployeeRegigithub.com/tej11695/tej11695/List_API 豆荚'SDWebImage‘荚'Alamofire','4.9.1’
https://stackoverflow.com/questions/44285817
复制相似问题