Cardiff, being the Welsh capital, is bigger than Swansea. So it has more clubs, busier etc. The uni and accommodation are slightly more spread out too.
Swansea though is right by the beach and has most of its nightclubs in one street which makes for a fun night out. There are lots of parks and green spaces which make it a really nice place to actually live and its pretty compact with campus' and accommodation. It's only 40 mins from Cardiff by train too and that makes it easy to get around the rest of the country if you want to go home a lot.
In terms of rankings, that depends on your subject. It's worth looking into modules and staff and seeing which suits your interests more. For me, Swansea had more modules and lecturers in my interest niche which is ultimately why I chose it. Plus the help they gave through the whole process and while at uni is useful as well.
If you can, go on open days or give them both a call with questions and that could help you decide.
Good luck!