Jer*_*ets 0 swift swift3 xcode8
我试图在Xcode 8中将C#示例转换为swift,但我一直遇到语法问题.查看代码的小例子:
public class ToonAPIClient {
private var APIManagerBaseAddress: URL!
private var APIBaseAddress: URL!
public init() {
APIManagerBaseAddress = URL(String: "https://path.to.baseurl/")
APIBaseAddress = URL(String: APIManagerBaseAddress + "append/path/data/")
}
}
Run Code Online (Sandbox Code Playgroud)
APIManagerBaseAddress我收到错误
参数标签'(String :)'与任何可用的重载都不匹配
并为APIManagerBaseAddress
二进制运算符'+'不能应用于'URL'类型的操作数 和'字符串'
任何帮助都很受欢迎,因为我尝试了一些语法可能性:)
-edit-感谢大家的帮助和建议!
首先,它是init(string:)不是init(String:)也用appendingPathComponent用APIManagerBaseAddress.
APIManagerBaseAddress = URL(string: "https://path.to.baseurl/")!
// you can add values like that in Swift
APIBaseAddress = APIManagerBaseAddress.appendingPathComponent("append/path/data/")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
143 次 |
| 最近记录: |