IPhone Study Notes

Source: Internet
Author: User

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:

 
 
  1. -(BOOL) can1_maction :( SEL) action withSender :( id) sender
  2. {
  3. Id menu = objc_msgSend (NSClassFromString (@ "UIMenuController"), NSSelectorFromString (@ "sharedMenuController "));
  4. // Or call respondsToSelector to determine whether a setMenuVisible method exists.
  5. If (menu)
  6. {
  7. Objc_msgSend (menu, NSSelectorFromString (@ "setMenuVisible:"), NO );
  8. }
  9. Return NO;
  10. }

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.