Rinse your swimsuit immediately after swimming.
The main thing. Chlorine and salt water are what fade suits, not the sun. Rinse it in cold water as soon as you’re done – even a quick dunk in a sink is better than letting it dry with chemicals in the fabric.
Machine washing is fine as long as you use a gentle cycle and skip the dryer. Hot water and heat break down spandex quick. Also, never use fabric softener. It messes with the elasticity and color retention.
Dry flat in the shade. Sunlight fades prints just as fast as chlorine does.
Future you will thank you when the same suit still looks new next summer.
