Does Swift support stored property with computed value?

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?

What I wish is that I could use queryItems as a simple var property

Computed property cannot be stored, by essence: they are computed on the fly.

So, what is your problem with a computed property ? What do you want to achieve that you can't ?

However, you could define a stored property and instantiate it in the init and each time you change queryItems_. But what'd be the interest ?

Note: having names so similar makes code much harder to read.

Does Swift support stored property with computed value?
 
 
Q