When they're not in the mood to swim.
When I was little, I was taken to piano lessons. I enjoyed being able to play, but there were weeks when I really didn't want to go, and weeks when I refused to practise. I would be furious with my mum for dragging me along to the classes, week in, week out, and there were many tears. But when I started to get better, I started to see a purpose in learning an instrument and get some enjoyment out of being able to play songs I recognised. I kept the lessons up into my teens, and learning the piano led to me learning other instruments. My social life built up around my music and some of my closest friends were made through playing in orchestras and bands. I will always be eternally grateful to my mum for encouraging me to go to those early piano lessons, because the long term gains have literally been life changing.
When you stick with a hobby, you get better at it. That boosts your self esteem, which makes you try harder and want to get even better, which further boosts your self esteem...which can become a really positive cycle.
That's not to say every parent should choose a hobby at random and force their child to stick with it come hell or high water - if he still makes the violin sound like a strangled cat after lots of practice, it might not be the right instrument - and it might be time to call it a day if he's not enjoying it. (If he's entirely tone deaf and having an awesome time, despite other people's wincing reactions, let him crack on!)
If a parent gives in the minute the child wants to give up, it sends a strong message to the child. That message can literally last a lifetime -
"if something's not making me happy right now, it's not worth doing."
But so often the opposite is true - the hardest things will give you the most reward, and they are the things worth sticking with. The gratification won't be instant, but it will be better.
I've always taught swimming, and I've also taught music and done tutoring. As teachers, we will always, always endeavour to engage the child, to make lessons enjoyable and fun. But we are with that child for half an hour each week, and it is the values of that child's parents that influence them the most.
To help your child stick with a hobby, make sure;
The hobby means something to them: They can't be forced to do something they have no real feel for and that has been chosen arbitrarily for them;
You choose the right classes and the right teacher to suit your child;
You value the hobby or interest as much as they do, and show them how much you enjoy hearing them play that instrument, or watching them play a sport;
They aren't too busy and tired: Choose one or two hobbies they can really stick with, so that they aren't oversaturated with after school activities and they're still getting lots of time at home - school is tiring enough!
You show them perseverance: Let them see you keep going with things you find hard - you are their most important role model!
Swimming is a great hobby to stick with. It has so many benefits in terms of health and water safety, and really is is a skill for life.