IPhoneStudy NotesRuntimeThis article is intended for beginners,RuntimeGenerally, when we translate it into runtime, it is loaded and executed only when the program is running.
The program is divided into several states: editing time-> Compiling Time (at this time, it will check the program for syntax errors and other related errors)-> static time-> Runtime
For example, some errors won't occur during compilation, that is, the program has no Syntax problems. However, during running, a running error may occur due to lack of resources or other factors. Runtime error!
For example, what we know before
C Runtime: The C run-time library contains initialization code and Error Handling Code (for example, divide by zero ). The program you write can run without the math library, but cannot process complex mathematical operations,
However, without the C run-time library, main () will not be called, and exit () cannot be responded. Because the C run-time library contains the most basic and commonly used functions for C program running.
So every time you use the runtime method in the file, make sure that the # import <objc/runtime. h>
(Location/usr/include/objc /.)
The method is not displayed.
For example, when you use the runtime objc_msgsend () method, it will compile and pass
What is the specific use of this runtime?
As follows:
For example, if you compile a program in a lower version of sdk2.x, and then block the copy and paste functions above 3.x, If you directly call a method such as setEnableCop ()
In this way, you are. when xSDK is compiled, an error is reported. The so-called method cannot be found because the method is in 3. versions above x will be provided, in 2. x cannot be found at all, so we cannot directly call the method.
Because the method calls in the iphone are transmitted in the form of messages, we can skip the compilation step and this method exists during the program's runtime judgment, if yes, we will implement blocking.
Code example:
- -(BOOL) can1_maction :( SEL) action withSender :( id) sender
- {
- Id menu = objc_msgSend (NSClassFromString (@ "UIMenuController"), NSSelectorFromString (@ "sharedMenuController "));
- // Or call respondsToSelector to determine whether a setMenuVisible method exists.
- If (menu)
- {
- Objc_msgSend (menu, NSSelectorFromString (@ "setMenuVisible:"), NO );
- }
- Return NO;
- }
Summary:IPhoneStudy NotesRuntimeThis article is helpful to you. The above concepts are summarized through self-exploration. If there is something wrong or inappropriate, please leave a message and learn together!