Invest in a Dry Egg/Box
My suggestion is to take as little valuables as possible, and carry them in the water with you when you go for a dip. What I usually do is I take some form of plastic ID, a bit of cash, a payment card and my phone. I leave everything else at home since most likely I won't need it on the beach. Everything I take easily fits in what is called a freediving dry egg/box which, as the name suggests, is a gadget used by divers to keep their stuff dry whilst in the water. These gadgets come in various different sizes, cost under €20 and look something like this (image courtesy of ScubaStore):
(source: watersportswarehouse.co.uk)
First thing you should do after purchasing your egg is to test ride its watertightness. Put a piece of paper in it, lock it up and throw it in a sink/bucket full of water. Then wiggle it around for a few minutes. Take it out, open it and check the paper: if it's wet you either did not close the egg properly or it leaks.
One possible way of carrying the egg whilst swimming could be replacing the lanyard with a longer one so that you can wear it diagonally across one shoulder like a shoulder bag. Other options include tying it to your swimming trunks, wearing it around your waist, your neck, or wearing a rubber weight belt of the type used by freedivers on which you can strap the box. The needed comfort also depends in how much swimming you are planning to do.
Locker Facilities at Barcelona's Beaches
Some of the beaches in Barcelona have lockers, according to the official municipal website. This information is everything but easy to find, since it's usually only listed on the individual webpage of each beach. The results of my searches show that the following beaches have lockers: Nova Icaria, Somorrostro, Bogatell, Mar Bella, Barceloneta (in Catalan only - Consigna). Hopefully this information is up to date. Note that the existence of lockers doesn't guarantee you to find a free/available one to use. Hence why I suggest the dry egg as a first option.