Matthew 7:6 is about not continuing to press sacred truth on people who have shown contempt for it over and over. In that culture dogs and swine were unclean animals that couldn’t tell a pearl from a pebble, and that’s the picture Jesus is painting (like this one).
One caution though. The verse comes right after “judge not,” and I don’t think that’s an accident. Jesus warns against harsh judgment and then immediately says we still need discernment, both at once.
I’ve seen it misused when people write someone off after one bad conversation. I had a coworker who mocked everything I said about faith for months, and at some point continuing to argue was doing more harm than good. So I stopped debating and kept being kind.