Yes, code signing (
https://en.wikipedia.org/wiki/Code_signing) accomplishes this. It's why you rarely see malicious code running on iPhones -- iOS won't load code into memory at all unless it's signed (except in very special cases like the JavaScript virtual machine, which has to generate code on the fly for performance).