Details
-
Type:
Bug
-
Status: Resolved
-
Priority:
Medium
-
Resolution: Duplicate
-
Component/s: Compiler
-
Labels:
Description
See forum thread for more details:
This property wrapper compiles, but not when used:
@propertyWrapper public final class Wrapper { public static subscript<EnclosingSelf>( _enclosingInstance observed: EnclosingSelf, wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Int?>, storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Self> ) -> Int? { get { return observed[keyPath: storageKeyPath].stored } set { let oldValue = observed[keyPath: storageKeyPath].stored if newValue != oldValue { // TODO: call wrapper instance with enclosing self } observed[keyPath: storageKeyPath].stored = newValue } } public var wrappedValue: Int? { get { fatalError("called wrappedValue getter") } set { fatalError("called wrappedValue setter") } } public init(str: String) { self.str = str } // MARK: - Private private let str: String private var stored: Int? }
When used, the compiler fails:
open class TestView: UIView { @Wrapper(str: "HelloWorld") public var testProp: Int? } /** Swift Compiler Error Type '_' has no member 'testProp' */
Replacing `Self` with `Wrapper` in the code fixes the issue. If I keep `Self`, I can also change the class to a struct to fix the issue.