You have probably decided to visit Barcelona not only for the famous architecture and the great tapas (& vino) but also for a bit of a sunshine fix, you should not be disappointed!
Personally my favourite months are May, June & September, it isn't too hot or crowded but it is warm enough to go to the beach, sit outside and definitely enjoy some cold Sangria. Even in the winter though, with the right clothes I have been know to sit outside on the beach for a Sunday lunch at Xiringuito Escribà.
August is the hottest month in Barcelona with an average temperature of 24°C (74°F) but highs of around 35°C (95°F). It is also the busiest month where most of the locals leave town. The coldest is January at 10°C (49°F) with the most daily sunshine hours at 9.5 in June. The wettest months are April & October with an average of 80mm of rain.
The best months to swim are July & August when the average sea temperature is 26°C (79°F), however it's fine for a dip from May through to October.