Casablanca, where it lies

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 ranges from 13 °C (55.5 °F) in January to 23 °C (73 °F) in August.
Here are the average temperatures.
Casablanca - Average temperatures
Min (°C)9911121517192019151210
Max (°C)171819202224262626242018
Min (°F)484852545963666866595450
Max (°F)636466687275797979756864

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

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 pass more frequently over this area than in southern Morocco (ie in cities like Agadir). Sometimes it can get cold at night, in fact 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 later they become more rare; some rainy days may occur still in April, and sometimes in May: occasionally there can be quite heavy showers. In the first half of June, there are often morning fogs and mists that keep the temperature low, so there's still spring-like weather. 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 on 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 becomes cooler. In addition, in autumn the first rains occur, with the return of Atlantic weather fronts.

Casablanca, Hassan II Mosque

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 March, when the sun still often shines, periods of bad and cloudy weather can occur.
Casablanca - Sunshine

The sea, quite cold in winter, remains a bit cool in the summer months, in fact it reaches 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.
Casablanca - Sea temperature
Temp (°C)171717181921222323222019
Temp (°F)636363646670727373726866

Best Time

The best time to visit Casablanca is from April to October, which is a mild or pleasantly warm period, with rare rains, and sunny as well, 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 a beach holiday, you can go from July to September, or the first half of October.