UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Beginner SwiftUI Question: Is using ViewModifier the best way to customize several repeated objects?

Forums > SwiftUI

Hi Everyone,

I'm working on a project that requires several TextFields to enter data. So there will be about 12 fields in each of three different views.

In the past when I've needed a bunch of modifiers added to several objects, I would just use ViewModifiers. That seemed to work great. Shout out to Paul Hudson for this post.

What I need to have now is for each of the TextFields show different placeholder data. They also need to match a certain look. Is using a ViewModifier the best way to do this? I feel like in UIKit I might use a class here, but I'm not sure.

My first thought is to use VM's for the bulk of the modifier's, then use specific entries per each TextField for their placeholder texts.

Is this the best way to do this?

Thank you all!

2      

I would create a custom TextFieldStyle and apply it to whatever container holds all your TextFields.

If you don't want to use that then, yes, apply your ViewModifiers to the container so they apply to all the TextFields within.

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.