There isn’t a one-size fits all approach. Firstly understanding why they don’t want to swim is an integral part. Allow them to verbalise this.
Without assuming their reason , it could be something as simple as they thought another child said something they didn’t like in their class. The life experience of interacting with different people has no substitute. Please talk to your pool deck supervisor before giving up.