Is it illegal to swear in front of police?

No. There is no general prohibition on swearing at or near the police. The police deal with unruly behaviour on a daily basis, and are expected to have a higher tolerance than ordinary members of the public. Unfortunately, that does not stop many of them from furthering petty prosecutions against those who do swear. It is quite common for overly-sensitive police officers to lay charges under section of the 5 Public Order Act, on the basis that the offender used threatening or words or behaviour, or disorderly behaviour, ‘within the sight or hearing of any member of the public who is likely to feel threatened or abused by it’. They tend to include themselves within that, despite the courts decision in DPP v Harvey 2011:

“Where witnesses have given oral evidence of an incident which forms the basis of a charge under section 5 of the Public Order Act 1986, but have said nothing and been asked nothing about experiencing harassment, alarm or distress, there is no sound basis for the court to reach that conclusion for itself. This is particularly so in the case of police officers because, as Glidewell LJ observed in Orum, they hear such words all too frequently as part of their job. This is not to say that such words are incapable of causing police officers to experience alarm, distress or harassment. It depends, as the court said in Orum and Southard, on the facts; but where a witness has been silent on the point it is wrong to draw inferences.”
DPP v Harvey 2011 at para 13

However, the Harvey case does not mean there is an overall immunity from swearing at the police. If the conduct goes beyond what a police officer would regularly be expected to encounter, such as racial abuse, and they genuinely suffer harassment, alarm or distress due to threatening, abusive or disorderly behaviour, then a charge could stand.