Loading Objective C code dynamically

帅比萌擦擦* 提交于 2019-12-06 05:53:00

Short answer: No

Not so short answer:

You could—in theory—include either the C, or C++ interface to the Clang compiler toolchain in your project, have that library compile the code you download, and then (through either NSBundle or direct interaction with dlopen) link that compiled code into your app.

In practice, if what you want to achieve is submitting to the App Store, this is explicitly prohibited by the Terms and Conditions.

You can't do this for deployment to the app store.

You wouldn't use plain text for this, you'd use a bundle (NSBundle). A bundle can contain both file (graphics, NIBs) resources and code so you can create your view classes and any associated NIBs, compile the bundle and then store it on your server. The app can then download the bundle and load it at runtime.

You can do it for non-app store apps. I have not tried this approach.

From Apple Docs:

The key to loading code from an external bundle is finding an appropriate entry point into the bundle’s executable file. As with other plug-in schemes, this requires some coordination between the application developer and the plug-in developer. You can publish a custom API for bundles to implement or define a formal plug-in interface. In either case, once you have an appropriate bundle or plug-in, you use the NSBundle class (or the CFBundleRef opaque type) to access the functions or classes implemented by the external code.

Loading Objective-C Classes If you are writing a Cocoa application, you can load the code for an entire class using the methods of NSBundle. The NSBundle methods for loading a class are for use with Objective-C classes only and cannot be used to load classes written in C++ or other object-oriented languages.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!