Hello babowa,
Thanks for reaching out to the Apple Support Communities. We understand that you're interested in learning how to track swimming with your iPhone.
There is not a feature on the iPhone to track your swimming. You can record the data in the Health app, as you have mentioned. Manage Health data on your iPhone, iPod touch, or Apple Watch. Your iPhone may have some water resistance, depending on the model, but it's not recommended to take your iPhone swimming. You can learn more about the water resistance of iPhone 7 and later here: About splash, water, and dust resistance of iPhone 7 and later.
The Apple Watch series 2 or newer, has the capability to track a swimming workout: Swim with your Apple Watch.
All the best.