Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

would be nice to be able to use "@Published" directive in earlier Swift versions that do not know it #235

Open
designerfuzzi opened this issue Jun 17, 2022 · 2 comments

Comments

@designerfuzzi
Copy link

designerfuzzi commented Jun 17, 2022

while trying to implement OpenCombine to mimic missing Combine Framework in example in Xcode 11.3.1 projects where Swift does also not support @Published directive (nor @Bind , @StateObject or @ObservedObject) one could do something like..

@propertyWrapper
struct Published<T> {
    var wrappedValue: T {
        willSet { /*...*/ }
        didSet { /*...*/ }
    }
    init(wrappedValue: T) {
        
        // * -- maybe magic here! -- */
        
        /* or do more specific stuff.. ^^
        switch (wrappedValue) {
        //case is Optional<Any>.Type :
            //break
        case is Bool :
            break
        case is Error :
            break
        case is Optional<Error>.Type :
            break
        default: break
        }
        */
        self.wrappedValue = wrappedValue
    }
}

to implement such feature in Swift version prior .. where @propertyWrapper directive is available.
So the question is what should such wrapper look like in its inner logic?

opened a question in StackOverflow

it could be wrapped also in preprocessor directives like #if !canImport(Combine) or similar to limit where it would be applied in projects

also see: swiftbysundell.com/accessing-a-swift-property-wrappers

@designerfuzzi
Copy link
Author

fixed. see: #217 (comment)

@designerfuzzi
Copy link
Author

methodical thinking pointed the right direction and with help the learning curve was sharp. Thnx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant