The phrase comes from the Christian Bible. Jesus is preaching and says: Do not give what is holy to the dogs; nor cast your pearls before swine, lest they trample them under their feet, and turn and tear you in pieces."
This means that scriptural truth or knowledge (pearls) should not be set before people people (swine, pigs) who do not or cannot appreciate their value.
Giving an expensive wine to someone who always buys the cheapest possible alcohol might be considered casting pearls before swine.