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

Referencing initializer 'init(wrappedValue:_:nilValidation:)' on 'Validated' requires that 'Published<String>' conform to 'Optionalable' #10

Closed
JulesMoorhouse opened this issue Jan 14, 2022 · 3 comments
Labels
question Further information is requested

Comments

@JulesMoorhouse
Copy link

JulesMoorhouse commented Jan 14, 2022

ValidatedPropertyKit Environment

  • ValidatedPropertyKit version:
    0.0.5

  • macOS version:
    11.6.2

  • Xcode version:
    13.2.1

  • Dependency manager (Carthage, CocoaPods, SPM, Manually):
    SPM

What did you do?

I'm using a view model.

import CoreData
import Foundation
import ValidatedPropertyKit

extension EditView {
    class ViewModel: NSObject, ObservableObject {
        let item: Item
        let add: Bool
        let hasRelationship: Bool

        private let dataController: DataController

        @Validated(!.isEmpty)
        @Published var title = "" <= error
        // @Published var title: String <= error 

What did you expect to happen?

To access the variable as shown in the readme examples.

What happened instead?

Error....

Referencing initializer 'init(wrappedValue:_:nilValidation:)' on 'Validated' requires 
that 'Published<String>' conform to 'Optionalable'

I'm not sure why this is occurring?

Thanks in advance.

@SvenTiigi
Copy link
Owner

Hi @JulesMoorhouse,

As you are applying the @Validated property wrapper to an @Published declared property the resulting type of the Validated property wrapper is a Published<String> which results in a compile error as the isEmpty validation rule can only be applied to types that conform to the Collection protocol.

PS: The error message that Xcode shows is a little bit confusing the correct error message should be:

Static property 'isEmpty' requires that 'Published<String>' conform to 'Collection'

@SvenTiigi SvenTiigi added the question Further information is requested label Jan 14, 2022
@JulesMoorhouse
Copy link
Author

Thanks for your reply @SvenTiigi what do you suggest I do to fix the problem.

@SvenTiigi
Copy link
Owner

As the Published type does not expose a wrapped value there is sadly no way to access the underlying value to validate.

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

No branches or pull requests

2 participants