我正在尝试将Lyft API与iOS 11和Swift 4结合使用,并且在第二行收到错误,这是



我不确定这意味着什么,以及如何解决它。任何帮助表示赞赏,谢谢!

let queryItems = parameters
    .sorted { $0.0 < $1.0 }
    .flatMap { components(forKey: $0, value: $1) }
var urlComponents = URLComponents(url: mutableURLRequest.url!, resolvingAgainstBaseURL: false)
urlComponents?.queryItems = (urlComponents?.queryItems ?? []) + queryItems //error here

最佳答案

我想您需要先将其设置为局部变量,然后再对其进行更改,请尝试以下操作:

var urlComponents = URLComponents(url: mutableURLRequest.url!, resolvingAgainstBaseURL: false)
var localVariable = urlComponents
urlComponents?.queryItems = (localVariable?.queryItems ?? []) + queryItems

关于swift - 对 'urlComponents'的访问重叠,但修改需要排他访问,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46126574/

10-11 02:17