Hello,
I've heard of the error "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions"
before, but never seen it myself.
I was surprised to find it with this, seemingly simple code:
public struct HikVisionCamera: Codable {
var localIPAddress: String
var username: String
var password: String
var channel: Int
func srcURL() -> String {
return "http://" + username + ":" + password + "@" + localIPAddress + "/ISAPI/Streaming/channels/" + channel + "/picture"
}
}
Is this a bug? Do I really need to break this down into sub-chunks?
[Edit]
Hmmm, I see that I have to create a String from the Int as String won't interpolate the Int directly - the following code does work.
Should my previous code confuse the type-checker that much?
Thanks
public struct HikVisionCamera: Codable {
var localIPAddress: String
var username: String
var password: String
var channel: Int
func srcURL() -> String {
let userPass = username + ":" + password
let path = "/ISAPI/Streaming/channels/" + String(channel) + "/picture"
let src = "http://" + userPass + "@" + localIPAddress + path
return src
}
}
[edit 2] - just to be clear - the breaking-down didn't solve the problem, but it helped me find where the issue was.