Is it possible to convert NSString to regular Objective-C code

For example, I have

NSString *string = @"return sharedInstance;";

I have a class method

+ (id)sharedInstance;

Is it possible to convert this string to simple code and use it in my method? This would be very useful for debugging. Suppose I have a method in which I want to test some code (let it be simple return values, is it possible?) I can just write code for the method and test the new code at runtime.

+5
source share
2 answers

What you described is not entirely possible. But there is support for certain things, for example, the ability to instantiate classes and invoke methods (theoretically) with strings:

NSClassFromString allows you to create instances of classes based on the passed string.

NSSelectorFromString "" .

.

, , -, , ( , , ). , ( Obj-C, , , ) , JavaScript UIWebView.

+5

C iOS - ; . C , , . .

+6

All Articles