ios - 无法在 Playgrounds 中使用 Alamofire 查找符号错误

标签 ios swift alamofire swift-playground

我正在使用 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

最佳答案

尝试将此添加到您的 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

确保再次运行 pod install 以重新生成 Pods 项目。然后使用 Command-Shift-K 清理构建,使用 Command-B 重建它,然后运行你的 playground。错误应该消失。

来源:https://learnappmaking.com/cocoapods-playground-how-to/

关于ios - 无法在 Playgrounds 中使用 Alamofire 查找符号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54083285/

相关文章:

android - Flutter - TextFormField 的异步验证器

ios - 在聊天中加载图像,像 whatsapp 一样在本地保存得更快

ios - swift : Use closure compatible with Objective-C block

swift - Xcode 10 : Auto insert closing braces bug

ios - Alamofire:遵循 HTTP 重定向(或不遵循)

ios - UISearchBar AutoLayout ios7 错误?

ios - Swift 动画重复次数

ios - 从 Branch.io 响应中获取值(value)并设置操作 (Swift)

ios - 找不到目标 'Alamofire' 的模块 'x86_64-apple-ios-simulator'

ALAMOFIRE 的 JSON_encode