Both are sports and competitions are held in both events.
When we float on water surface by pushing water down, and we push water behind with hands to move forward, it is called swimming. In swimming we travel in water from one end of a pool to the other end. The pool could be 20 meters to 50 meters long. For a long swimming sport, one needs a lot of stamina and power in the shoulders. Swimming events take in minutes because of the number of laps to do. It is a longer duration sport.
In diving the divers climb to a diving board around 3 to 8 meters high and jump into water in the swimming pool. They display various artistic movements in air like rotating, spinning, somersaulting remaining absolutely still etc. The divers have to make the geometries perfect in the complex moves. Diving finishes in a few seconds.