Yes, you can! Some people choose not to submerge their locks, and that’s an option if you’re worried about it. However, you can definitely swim with them as long as they’re mature enough to withstand the washing you’ll need to do afterward.
For pool swimming, saturate your hair with tap water before entering the pool to limit salt and/or chlorine absorption in your hair. After leaving the pool, wash and rinse your hair thoroughly because chlorine buildup can damage hair very horribly if it doesn’t get washed out. Consider using a swimmer’s shampoo if you swim in chlorinated pools to effectively remove the damaging chemicals from your hair. Lastly, this process can be drying to your hair, so consider moisturizing it with diluted conditioner, aloe vera, rosewater, coconut milk, or glycerin — whatever fits your comfort levels and climate.
In natural bodies of freshwater, this washing regimen isn’t as necessary. However, there can be quite a lot of small organic materials in natural bodies of water, so try to rinse those flakes out of your hair upon exiting.