Map from Google - Casablanca

In Casablanca, a 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 is able temper the summer temperatures. The climate in itself is great, but unfortunately the city is polluted; pollution is favored by the stability of the weather, especially in spring and summer.
The average temperature goes from 13 °C (55.5 °F) in January, to 23 °C (73 °F) in August.
Here are the average temperatures.
Average temperatures - Casablanca
Min (°C)9911121517192019151210
Max (°C)171819202224262626242018
Min (°F)484852545963666866595450
Max (°F)636466687275797979756864

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

Winter, from December to February, is mild: the average temperature in January is about 13 °C (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 temperature can reach freezing (0 °C or 32 °F). On the other hand, the wind from the desert can cause some hot days, with maximum temperatures about 28/30 °C (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 30/32 °C (86/90 °F).

Summer, from mid-June to September, is pleasantly warm. The weather is fine 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 38/40 °C (100/104 °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 21 °C (70 °F) in June, 22 °C (72 °F) in July and October, and 23 °C (73 °F) in August and September, when all in all it becomes acceptable for swimming.
Here are the average sea temperatures.
Sea temperature - Casablanca
Sea (°C)171717181921222323222019
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.