If you are caught in a rip current, there are actions you can take to swim to safety. Here are some recommendations from the National Weather Service:
Remain calm to conserve energy and think clearly.
Never fight against the current.
Think of it like a treadmill that cannot be turned off, which you need to step to the side of.
Swim out of the current in a direction following the shoreline. When out of the current, swim at an angle -- away from the current -- towards shore.
If you are unable to swim out of the rip current, float or calmly tread water. When out of the current, swim towards shore.
If you are still unable to reach shore, draw attention to yourself by waving your arm and yelling for help.