TagKit icon indicating copy to clipboard operation
TagKit copied to clipboard

Why not storing the text of TagTextField locally?

Open Vithanco opened this issue 1 year ago • 1 comments

I wonder why it has to be provided from outside and not internally?

@State private var theText: String = ""

If needed, then we can add

    private var theTextBinding: Binding<String>{
        return Binding<String>(
            get: { return self.theText.slugified()},
            set: { self.theText = $0.slugified()}
        )
    }

Woudn't that be easier?

Vithanco avatar May 12 '24 17:05 Vithanco

Hi @Vithanco

I'm not sure, I will check :)

danielsaidi avatar May 21 '24 09:05 danielsaidi

Closing this due to inactivity.

danielsaidi avatar Oct 06 '24 12:10 danielsaidi

nice... I didn't know that one can close issues that were not looked into... :-) Did you want any input from me?

Vithanco avatar Oct 07 '24 07:10 Vithanco

Oh damn, I've been working with most of my open-source projects in parallel for the last few days, to update them for Swift 6, and must have confused two tickets in the many open tabs I had going on.

Sorry about that, and thank you for letting me know!

Which text is it that you have to provide from the outside, that you'd like the library to resolve internally?

danielsaidi avatar Oct 07 '24 10:10 danielsaidi

it is the just that the TagTextField needs an externally created text instead of using an internal one?

    public init(
        text: Binding<String>,
        placeholder: String = "",
        configuration: SlugConfiguration = .standard
    ) {
        self.text = Binding<String>(
            get: { text.wrappedValue.slugified() },
            set: { text.wrappedValue = $0.slugified() }
        )
        self.placeholder = placeholder
        self.configuration = configuration
    }

It is fine to provide the possibility for externally created, but wouldn't it make sense to have it locally initiated if this functionality isn't needed?

KneupnerTrackunit avatar Oct 07 '24 10:10 KneupnerTrackunit

sorry, different profiles, same user

KneupnerTrackunit avatar Oct 07 '24 10:10 KneupnerTrackunit

Hi @KneupnerTrackunit

I see what you mean. However, the idea with TagTextField is to be a replacement for a regular TextField, where the text you type is automatically slugified. Just like TextField, it takes a binding and leaves the utility of the text up to you.

How would you use the text field if it could also set up an internal binding. How would you then access the slugified text?

danielsaidi avatar Oct 11 '24 07:10 danielsaidi

Hi Daniel! Thanks for coming back to me. I fear I stole your time. I think when I wrote this, I didn't understand SwiftUI properly. I now went through my code and indeed, it looks completely fine as you designed it. My apologies and thank you for entertaining me. Klaus

KneupnerTrackunit avatar Oct 15 '24 06:10 KneupnerTrackunit

No worries, I'm happy to have these discussions! :)

Wishing you all the best in your future SwiftUI endeavors.

danielsaidi avatar Oct 15 '24 22:10 danielsaidi