Map from Google - Casablanca

In Casablanca, city located on the Atlantic coast of Morocco, the climate is very mild, similar to that of the coast of Southern California: in fact along the coast of the Atlantic Ocean a cold current flows, which can cause some morning fogs and temper the summer temperatures. The climate in itself is great, but unfortunately the city is polluted, and pollution is favored by the stability of the weather, especially in spring and summer.
The average temperature goes from 55.5 °F in January, to 73.5 °F in August.
Here are the average temperatures.
Average temperatures - Casablanca
Min (°F)484852545963666866595450
Max (°F)636466687275797979756864

Rainfall is not abundant, since it amounts to 16.5 inches per year, and it follows a Mediterranean pattern, being concentrated from October to April, while in summer it almost never rains.
Here is the average precipitation.
Average precipitation - Casablanca
Prec. (in)

Winter, from December to February, is mild: the average temperature in January is about 55.5 °F. There are many sunny periods, alternating with periods of bad weather, due to Atlantic depressions, which here pass more frequently than in southern Morocco (ie in cities like Agadir). Sometimes it can get cold at night, so that the minimum temperatures can reach freezing. On the other hand, the wind from the desert can cause some hot days, with maximum temperatures about 82/86 °F.

Spring, from March to mid-June, is mild or pleasantly warm, and often sunny. In March, Atlantic disturbances still pass quite frequently, but then become more rare; some rainy days may occur still in April, and sometimes in May: occasionally there may be quite heavy showers. In the first half of June, as a matter of fact it's still spring, because there are often morning fogs and mists that keep the temperature low. Sometimes, however, the wind from the desert can raise the temperature to 86/90 °F.

Summer, from mid-June to September, is pleasantly warm. The weather is nice and it practically never rains, but in the morning fogs and mists can form (though less frequently than in Agadir). Waves of hot weather are much rarer than in the southern Moroccan coast, and are also less intense, however, when they occur, the maximum temperature can reach 100/105 °F.

Autumn, in October and November, is pleasantly warm and sunny at first, then it gradually become cooler. In addition, in autumn the first rains occur, with the return of Atlantic weather fronts.

The amount of sunshine in Casablanca is good from April to September or mid-October, when good weather prevails, although a few hours of sunshine may be lost because of morning mists, while from November to February, when the sun still often shines, periods of bad and cloudy weather may occur.

Casablanca, Hassan II Mosque

The sea, quite cold in winter, remains a bit cool in the summer months, as it touches 70 °F in June, 72 °F in July and October, and 73 °F in August and September, when all in all it becomes acceptable.

Here are the average sea temperatures.
Sea temperature - Casablanca
Sea (°F)636363646670727373726866

When to go

The best time to visit Casablanca goes from April to October, being a mild or pleasantly warm period, with little rain, and sunny too, although there may be some morning fogs. In April, May and October, sometimes it can rain. Heat waves from July to September, in this part of the coast are so rare, that you can ignore them in your travel plan.
For swimming, you can go from July to September, or the first half of October.