Swim parallel to the beach. The End.
Well, what this amounts to is "stay calm and stay afloat". Because if you are being "swept out" this is a temporary situation. You need to conserve your energy to swim back in after you get out there, and things have calmed down. Or, if you end up way out there, stay calm and stay afloat. They will come for you. Be waiting.
I was once canoeing alone in the Gulf of Mexico off a beach at Sanibel Island, and got caught in a a rip tide that took me out to sea. It was pretty scary.
I figured out that I had to start paddling parallel to the beach to get to an area outside the rip tide from which I could paddle back to land.
It was really very hard to do, and took quite a bit of time.
I can easily imagine that it would be even harder for a a swimmer to do that. I doubt an average bather would have the strength to get the job done. I'm pretty sure I couldn't have done it.
Some things can be fought and some things need to be conceded to - anyone who has ever had a wave crash down and bounce you along the bottom for a bit understands this...like being pushed by a locomotive.