首页 > 解决方案 > 在 Playgrounds 中使用 Alamofire 无法查找符号错误

问题描述

我正在使用 Playgrounds,并通过 Podfile 安装了 Alamofire 和 SwiftSoup。我可以使用 Alamofire 从 URL 中检索 HTML,URLSession但希望这样做。我的代码如下。

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

标签: iosswiftalamofireswift-playground

解决方案


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


推荐阅读