1 min readNov 28, 2017
Hi Iijie,
swift extensions cannot have stored properties, they can only have computed properties. even if you are able to set some value to a computed property, it will give you value which you write in get {}. in other word you may not use its value as you do with stored properties. If I am not wrong you are trying to store some value to it.
Still if you want to try `set` thing, here is the modified code for you:
public protocol MyHelperCompatible {
associatedtype someType
var my: someType { get set }
}public extension MyHelperCompatible {
public var my: MyHelper<Self> {
get {
return MyHelper(self)
}
set(newValue) {
my = newValue
}
}
}public struct MyHelper<Base> {
let base: Base
init(_ base: Base) {
self.base = base
}
}extension UIView: MyHelperCompatible {}extension MyHelper where Base: UIView {
public var width: CGFloat {
set(newValue) {
width = newValue
}
get {
return 0.1 //some computed value
}
}
}
let me know if this makes sense.
cheers.