This may sound strange, but I encounter real world need on this.
private var queryItems_: [URLQueryItem]?
private var queryItems: [URLQueryItem]? {
get {
if queryItems_ == nil {
if !queries.isEmpty {
queryItems_ = queries.map { (key: String, value: String?) in
return URLQueryItem(name: key, value: value)
}
}
}
return queryItems_
}
}
/// Query strings
public private(set) lazy var queries = [String: String?]() {
didSet {
queryItems_ = nil
}
}
The queryItems will be (re)created on get
if queries property was changed. What I wish is that I could use queryItems as a simple var property but let me do my logic in its getter. Is this supported already?