This isn't exactly what you're asking for but on Android: Settings > Sound > Do Not Disturb > Allowed in Priority Only > Calls From Contacts Only (or Calls from Starred Contacts Only if you really want to lock it down).
Optionally enable: If the same person calls a second time within a 15 minute period, allow it (might allow someone really trying to reach you to get through, might also allow a spam caller through).
I tried this on iOS and it doesn’t work well because it turns off all other notifications.
While calls do get through from your contacts, you don’t get notifications for anything.
I really just want a contacts whitelist, but since that isn’t an option I use nomorobo which is a subscription service that works really well to block spam calls for $2/month. It’s an iOS app, focuses on not uploading your stuff to their servers, and doesn’t collect your call logs.
I have an s7 and I star every important number. I use use IFTTT to enable DND automaticaly at 22.00 and disable it at 8.00. Is very convinient. I can also filter an app for example whatsapp to pass DND and ring.
Optionally enable: If the same person calls a second time within a 15 minute period, allow it (might allow someone really trying to reach you to get through, might also allow a spam caller through).