It depends. The smaller and lightweight harness is perfectly safe for a dog to swim in it. Just remember, only harness, no leash. A leash could easily get stuck and cause some serious problems.
Bigger harnesses with stuffed parts are not suitable because they will get wet and thus heavier, which will bring your pup in danger of drowning. The best solution is a life jacket for dogs, made just for the purpose of helping dogs to swim, float and have fun in the water.