我正在使用Playgrounds,并通过Podfile安装了Alamofire和SwiftSoup。我可以使用URLSession
从URL检索HTML,但希望使用Alamofire这样做。我的代码在下面。
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)
}
}
}
我不确定为什么会出现以下错误。
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
答案 0 :(得分:2)
尝试将其添加到您的class PostData
{
public string[] userRoles { get; set; }
public string email { get; set; }
}
[HttpPost]
public async Task<IActionResult> SaveUserRoles([FromBody]PostData postData)
{
return Ok();
}
Podfile
确保再次运行pod install以重新生成Pods项目。然后使用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
清理构建,使用Command-Shift-K
重建构建,然后运行您的游乐场。该错误应消失。