在模拟器中工作,但不在真实设备上运行Swift XCode Alamofire

时间:2018-12-07 08:39:34

标签: swift xcode swift4 alamofire xcode10

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

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

这是我的代码ViewController.swift

导入UIKit

导入Alamofire

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()
}

}

1 个答案:

答案 0 :(得分: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的新文件