Some ideas (in no particular order):
1. Do your absolute best, always change for class, rack up a good grade in the other units. Refuse to change for class during the swimming unit. Take the GPA hit. This does not work if you are in high school and shooting for something like the top 10% of your class (you didn't say if it was HS or MS).
2. Talk to your pediatrician and tell hir that you're trans but don't want to come out to your parents. By law, this conversation is totally confidential.* Ask for a doctor's note excusing you from gym due to your "birth defect" or other reason that zie can justify putting down.
*If your doc busts this and outs you to your parents, file a lawsuit and use the money to go to a school without a pool.

3. The idea someone had about asking to wear the shirt.
4. Ask your teacher if you can do an alternative unit or class. In my school, we could opt for a.m. weight training instead of gym.
5. Fake an ankle sprain. At the doctor's office, make sure to wince a lot when they feel around your non-swollen ankle. This may get you a note, though I'm not sure. I have successfully faked PT's into thinking my sprain was better than it was, but I've never tried making it seem worse.
6. In some schools, varsity athletes are PE-exempt. Join a sports team?
7. Cut class. You'll get in trouble and serve some detention or ISS. Not highly recommended but perhaps a last resort.
8. "Suck it up." Not a great option, but still worth listing as it is an option. :/
9. Ask if you could get credit for taking a swimming course elsewhere, like at night at the YMCA. You would still need to wear a swimsuit somewhere, but at least not in front of your peers.
10. Pack for swimming. Freak 'em all the hell out! (okay, not realistic, but listed just for the smile/giggle factor of imagining that...

11. Change into the suit one time - on the first day of the swimming unit. Fake a panic attack when you catch sight of the pool - I mean full-on rocking in fetal position on the ground like Ricky Sway in "The Client." When you get taken to Guidance, tell them some story about watching <insert horror movie about drowning here - do some research> and ever since then being unable to go near a pool. Act like you're mortified and you wish you could, and you've never told anyone this before so please don't call your parents. They still will, but at least it covers the fact that your 'rents will have no idea WTF you're talking about. NOTE: this will not work if you've gone swimming in recent memory and your parents call it out.
12. Only if you're SUPER bold: wear a monstrously risque swimsuit. Think Playboy bunny. They'll make you put your clothes back on. Wash, rinse, repeat as necessary. Might land you in disciplinary trouble. :/
Running out of ideas - best of luck! :O