如何将Alamofire的Get请求中的数据反映到UI View Controller

时间:2018-08-23 14:30:53

标签: ios swift alamofire

如何使用 Alamofire 反映JSON词典中的数据,以执行验证以检查输入的密码对我的UI View Controller是否有效。我已经获得了从API中获取数据的成功结果,但是我不知道我的视图控制器如何从API中读取值以验证输入的密码。请帮助我。......Successful result in printing PasscodeJSON

eventDetails for ViewController but cannot read data from APIService

APIService

res.headers('x-auth', token)

ViewController

class APIService
{
   let eventAPIKey: String
   let eventBaseURL: URL?

    //static let kEventID = "id"
    init(APIKey: String)
    {
    self.eventAPIKey = APIKey
     eventBaseURL = URL(string: BASE_URL)
     }

     func validatePasscode(passcode: String, completion: @escaping (Event?) -> Void)
    {
     if let passcodeURL = URL (string: "\(PASSCODE_CHECKER_URL)/\(passcode)") {


    Alamofire.request(passcodeURL, method: .get).responseJSON { (response) in

        switch response.result{
        case .success:
            if let passcodeJSON = response.result.value {
                print(passcodeJSON)
                completion(passcodeJSON as? Event)



            }
        case .failure(let error):
            print("\(error)")
            }
        }

       }
    }


 }

0 个答案:

没有答案