I'm currently trying to send an https request from an Apple Watch to an iPhone using Alamofire, which I understand is the only way to do this. I've tried installing using Cocoapods, but this hasn't worked and has resulted in an error each time. So, I've tried installing manually, and, while I believe that installed, it keeps giving me a "module not found". I've attached the current state of the project with the networking client and the view controller. If anyone has any advice related to the installation process or the coding in general, that would be wonderful.
import Foundation
import Alamofire
class NetworkingClient {
typealias WebServiceResponse = ([[String:Any]]?, Error?) -> Void
func execute( url: URL, completion: WebServiceResponse){
Alamofire.request(url).validate().responseJSON {response in
if let error = response.error {
completion(nil,error)
} else if let jsonArray = response.result.value as? [[String: Any]]{
completion(jsonArray, nil)
} else if let jsonDict = response.result.value as? [[String: Any]]{
completion([jsonDict],nil)
}
}
}
}
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
private let networkingClient = NetworkingClient()
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func executeRequest( sender: Any){
guard let urlToExecute = URL(string: "https://jsonplaceholder.typicode.com/posts/1") else{
return
}
networkingClient.execute (url: urlToExecute) { (json, error) in
if let error = error {
self.textView.text = error.localizedDescription
} else if let json = json {
self.textView.text = json.description
}
}
}
}