Image copyright Getty Images Image caption First Minister Nicola Sturgeon was questioned by opposition MSPs about named person ahead of Mr Swinney's statement

The Scottish government has scrapped its controversial plan to appoint a named person to safeguard the welfare of every child in the country.

The scheme, which was branded a "snooper's charter" by opponents, was due to be introduced three years ago.

But it was delayed when the Supreme Court ruled that part of the plan breached Human Rights laws.

Education Secretary John Swinney has now confirmed that he will withdraw the named person legislation.

The Conservatives said the move was a "complete humiliation" for the government.

They called on Mr Swinney to apologise for the "millions of pounds of taxpayers' money that has been wasted" and to "all the professionals on the front line who have been faced with endless bureaucracy around this policy".

The scheme would have seen a named person - usually a teacher or health visitor - act as a clear point of contact for every child from birth until the age of 18.

In its ruling in July 2016, the Supreme Court said the aim of the policy was "unquestionably legitimate and benign", but that proposals around information-sharing breached the right to privacy and a family life under the European Convention on Human Rights.

The judges said the proposals meant it was "perfectly possible" that confidential information about a young person could be disclosed to a "wide range of public authorities without either the child or young person or her parents being aware".

Mr Swinney subsequently set up an expert panel which was tasked with finding a way of making named person compatible with the Supreme Court ruling.

But the panel was unable to write a workable code of practice on information sharing, and concluded that doing so "would not be desirable" as the complexity would make it difficult to understand or apply in practice.

Mr Swinney told the Scottish Parliament on Thursday afternoon that the "mandatory named persons scheme for every child, underpinned by law, will now not happen" and that "we will withdraw our bill and repeal the relevant legislation."

He said that existing, voluntary schemes that provide a point of contact for support will continue - but only for those councils and health boards that wish to provide them, and only for parents who wish to use them.

Mr Swinney said: "In this way, we will support our children and young people so that they can thrive and rise to the challenges and opportunities that life brings."

He added: "I believe that today we have taken an important step forward in providing families and practitioners with certainty about how information-sharing can support well-being in a transparent way which respects the rights of everyone."

Earlier on Thursday, the government launched an investigation after details of Mr Swinney's statement were leaked in advance to the Herald newspaper.

What did the Scottish government want to do?

Image copyright Getty Images Image caption The named person for most school-age children would have been a teacher

The government says it is committed to making Scotland "the best place in the world for children to grow up".

As part of its Getting it Right for Every Child strategy, it proposed giving all children and young people from birth to 18 years access to a named person under the Children and Young People (Scotland) Act 2014.

The named person was intended to be single point of contact if a child or their parents wanted information or advice, or if they wanted to talk about any worries and seek support.

They would also be a point of contact for other services if they had any concerns about a child's wellbeing.

The law was due to come into force across the country on 31 August 2016 but the policy had already been rolled out in parts of Scotland, including Highland, Edinburgh, Fife, Angus and South Ayrshire.

Why was it so controversial?

The legal challenge was launched by the No to Named Persons (NO2NP) coalition, which includes the Christian Institute, Care (Christian Action Research and Education), Tyme Trust and the Family Education Trust.

The group argued that the named person legislation would lead to "unjustified and unjustifiable state interference with family rights" and that responsibility for monitoring a child's wellbeing should be the role of the parent, not the state.

Their arguments had previously been dismissed as "hyperbole" by the Court of Session in Edinburgh, which said named person did not diminish the role of parents and had "no effect whatsoever on the legal, moral or social relationships within the family".

Some organisations warned that the legislation's wording meant the role of the named person was open to wide interpretation.

And the Scottish Parent Teacher Council published the results of an online survey in 2013 which it said suggested "high levels of concern" from parents about the proposals.

However, children's charities including Barnardo's, Aberlour, Action for Children and Children 1st accused opponents of the scheme of making "inaccurate and unjustified" statements about named person.

What has the reaction been?

NO2NP said Mr Swinney's statement "effectively consigns the detested Big Brother scheme to the legislative dustbin", and predicted that parents would be "delighted" by the move.

But the group said the government should have ditched the plan "a long time ago and saved a lot of time and a lot of money and a lot of anxiety."

Scottish Conservative education spokeswoman Liz Smith said: "This is a complete humiliation for the SNP. Common sense should have told them years ago that this policy was both universally unpopular and unworkable.

"In the interim, millions of pounds of taxpayers' money has been wasted as has the time that should have been spent addressing the challenges facing our most vulnerable children."

The EIS teaching union said named person was originally conceived as a "genuine attempt to ensure that the protection afforded to vulnerable and at-risk young people across Scotland was as robust as it could be, to ensure that children did not fall through cracks in the system, and to strengthen the support to those with needs requiring a multi-agency approach.

"While legislation is not always the best route to achieving such aims, we must not lose sight of the need that still exists to deliver on that ambition."