Search code examples
c#iosxamarin.iosinterpreteraot

iOS C# Interpretation VS Code Generation


I read that it is not possible to emit IL code on iOS, and hence the expressions are pre-compiled with AOT option, and the Expressions that cannot be AOTed are interpreted. My question is why does iOS allow interpretation but not runtime code generation, isn't it the same except for the performance. Why is that interpretation is not a security issue but the code generation is?


Solution

  • The Interpreter, as the name implies, allows you to interpret at run time some C# parts of your application while compiling the rest ahead of time as usual.

    The Generator, called btouch in Xamarin.iOS, takes these definition files and uses .NET tools to compile them into a temporary assembly. However, this temporary assembly is not useable to call Objective-C code. The generator then reads the temporary assembly and generates C# code that can be used at runtime.

    Why is that interpretation is not a security issue but the code generation is?

    This is why, for example, if you add a random attribute to your definition .cs file, it won’t show up in the outputted code. The generator doesn’t know about it and therefore btouch doesn't know to look for it in the temporary assembly to output it.

    Reference Links : iOS App Architecture , Introducing the Xamarin.iOS Interpreter