在模拟器中工作但不在Real设备swift xcode alamofire上工作

问题描述 投票:-5回答:1

在模拟器中工作但不在设备上工作我从api获取数据它在模拟器上正常工作但不在真实设备中工作

并给出错误没有这样的模块'Alamofire'

这是我的代码ViewController.swift

导入UIKit

进口Alamofire

class ViewController:UIViewController,UITableViewDelegate,UITableViewDataSource {

@IBOutlet var tableview: UITableView!

var TeamArray = [AnyObject]()
var BackArray = [AnyObject]()
 var countnew = 0
var timer = Timer()
override func viewDidLoad() {
    super.viewDidLoad()

    Alamofire.request("https://www.WebLink.com/api/").responseJSON{
        response in

        if let DataResult = response.result.value{

             if let dictionary = DataResult as? [String: Any] {
                if let Result1 = dictionary["result"] as? [String: Any]{
                    if let nestedDictionary1 = Result1["inPlayEvents"] as? NSArray, let description = nestedDictionary1.value(forKey: "market") as? [[String: Any]],let description1 = description.first?["runners"] as? [[String: Any]],let BAck = description1.first?["back"] as? NSArray{

                        print("JSONResdsd : \(nestedDictionary1)")
                       // print("JSONEvent : \(description)")
                        self.TeamArray = description as [AnyObject]
                        self.BackArray = BAck as [AnyObject]

                         self.timer = Timer.scheduledTimer(timeInterval:1.0, target: self, selector: "sayHello", userInfo: nil, repeats: true)

                    }
                }
            }

        }
    }
    // Do any additional setup after loading the view, typically from a nib.
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return TeamArray.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as?
    CustomTableViewCell

    let title = TeamArray[indexPath.row]["start"]
    let price = BackArray[indexPath.row]["price"]

    let x : Double = title as! Double
    let myString = String(x)
    let pricenew : Double = price as! Double
    let pricestr = String(pricenew)
    print("Price : \(pricestr)")
    print("INT : \(title)")
    //let BPrice = BackArray[indexPath.row]["price"]
 //  ToastView.shared.short(self.view, txt_msg: "HJJDFKH\(String(describing: BPrice)))")
    cell?.TitleLabel.text = String (myString)
    cell?.Back.text = String (pricestr)
   // cell?.Back.text(\())
    return cell!
}

@objc func sayHello()
{
    self.tableview.reloadData()
}

}

swift xcode swift4 alamofire xcode10
1个回答
1
投票

你能告诉我你是怎么安装Alamofire的吗?您可以查看他们的GitHub自述文件页面:https://github.com/Alamofire/Alamofire/tree/4.8.0有几种方法可以将此库添加到项目中。我会建议你使用Cocoapods:

1)安装CocoaPods:

gem install cocoapods

2)在项目文件夹中创建Podfile

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
   pod 'Alamofire', '~> 4.7'
end

<Your Target Name>替换为您的目标名称。

3)运行:

pod install

4)关闭项目并在Xcode中打开一个名为<Your Project Name>.xcworkspace的新文件

© www.soinside.com 2019 - 2024. All rights reserved.