I'm using Playgrounds and have Alamofire and SwiftSoup installed via Podfile. I can retrieve the HTML from the URL with URLSession
but wish to do so with Alamofire. My code is below.
let url = "https://www.nba.com/warriors/stats"
Alamofire.request(url, method: .post, parameters: nil, encoding: URLEncoding.default).validate(contentType: ["application/x-www-form-urlencoded"]).response { (response) in
if let data = response.data, let _ = String(data: data, encoding: .utf8) {
do {
print(data)
}
}
}
I'm not sure why I'm getting the following error.
error: Couldn't lookup symbols:
Alamofire.DataRequest.response(queue: Swift.Optional<__C.OS_dispatch_queue>, completionHandler: (Alamofire.DefaultDataResponse) -> ()) -> Self
protocol witness table for Alamofire.URLEncoding : Alamofire.ParameterEncoding in Alamofire
type metadata accessor for Alamofire.DataRequest
Alamofire.DataRequest.validate<A where A: Swift.Sequence, A.Element == Swift.String>(contentType: A) -> Self
Alamofire.request(_: Alamofire.URLConvertible, method: Alamofire.HTTPMethod, parameters: Swift.Optional<Swift.Dictionary<Swift.String, Any>>, encoding: Alamofire.ParameterEncoding, headers: Swift.Optional<Swift.Dictionary<Swift.String, Swift.String>>) -> Alamofire.DataRequest
protocol witness table for Swift.String : Alamofire.URLConvertible in Alamofire
static Alamofire.URLEncoding.default.getter : Alamofire.URLEncoding
type metadata for Alamofire.URLEncoding
Try adding this to your Podfile
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings.delete('CODE_SIGNING_ALLOWED')
config.build_settings.delete('CODE_SIGNING_REQUIRED')
end
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CONFIGURATION_BUILD_DIR'] = '$PODS_CONFIGURATION_BUILD_DIR'
end
end
end
Make sure to run pod install again to regenerate the Pods project. Then clean the build with Command-Shift-K
, rebuild it with Command-B
, and run your playground. The error should disappear.
Source: https://learnappmaking.com/cocoapods-playground-how-to/