Apple - Block all unknown numbers not in my Contacts from calling and messaging on my iPhone
Yes, albeit with some trade offs. See this link for some information. If you go to Settings, hit General > Do Not Disturb > Allow Calls From and select Contacts Only. This setting applies to SMS messages as well. Hopefully this is useful.
You can create a contacts group and add all (or desired) contacts to that group.
On your iPhone, enable Do Not Disturb. Go to Settings app → Do Not Disturb and select the group All Contacts from within Allow Calls From section under Do Not Disturb.
You can also create a Contacts group to selectively segregate contacts. To create a contacts group, refer to the Apple Support article, iCloud: Create a group and add contacts to it.
Update: Apparently an easier approach is to select All Contacts in the aforementioned step, instead of creating a group and selecting it. All Contacts option is available by default.