i've heard you should teach a dog to swim before its fear period hits (before the dog can think for itself and know what fear is) which is before 14-16 weeks. mine swam at 11 weeks. after its fear period then you should just let the dog gain confidence and go at its own pace.
my friend had a golden retriever that didnt swim until it was almost one. she would throw a ball into the water and the dog would run full speed to get it and then just slam on the brakes right at the edge of the water. when the dog finally swam it was a natural and didnt wanna get out. some dogs are fearless and some dogs just need more time to build up confidence.