ISO study notes, Study Notes

Source: Internet
Author: User

ISO study notes, Study Notes

Objective -- C One keyword @ property defines the variable function @ synthesize to implement the Variable Function two function alloc allocation memory init initialization new replace the above two functions to allocate memory, in addition, the modifier @ public @ protected @ private @ package @ public instance variable of the Three-rule 0 variable can be accessed anywhere. @ Protected instance variables can be accessed by declared classes and subclasses. All instance variables without explicit scope are @ protected. @ Private instance variables can only be accessed by declared classes. @ Package uses runtime modern. One @ package instance variable is actually @ public in the executable file image that implements this class, however, it is @ private (for runtime, see the apple documentation Runtime Programming Guide ). This type is most commonly used for instance variables of the framework class. @ private is too restrictive and @ protected or @ public is too open. Class 1 instance member variables (non-static variables) assignment/value can usually be in three ways, note that when assigning values to strings, you need to add the prefix @ before the string @; in addition, the access to these variables can only be accessed in non-static function conversion; A object. member variable @ protected @ public @ private B object-> member variable @ public C [object member variable set function] @ public @ protected @ private 2 static variable A Objective-C itself does not support static variables, however, since Objective-C is a super class of C language, you can use the static keyword of C language to create global variables. global variables are the same as static variables in Java, the class is initialized only when it is loaded for the first time. The call to the static variable B is released only when the program is destroyed, whether it is a value assignment or a value C static variable, it can also be defined in the method, but the static variable defined in the method can only be called in the Method. 3 dynamic function A Identifier-B call method [instantiate object function] C instance method on Stack 4 static function A identifier + B call method [class function] C static method allocate memory on the stack 5. The static method and the instance method distinguish A static method from the resident memory, the instance method is not, so the static method is highly efficient but occupies the memory. In fact, the methods are the same. In terms of loading time and memory usage, the static method is the same as the instance method, and is loaded when the type is used for the first time. Basically, there is no difference in the call speed. The static method B allocates memory on the stack, and the instance method is on the stack. In fact, it is impossible for all methods to allocate memory on the heap or stack. As code, methods are loaded into special code memory areas, this memory area is a non-writable C-instance method that can be called only after an instance is created. This is troublesome and does not require static methods. It is relatively simple. D. The static method is statically bound to the subclass rather than inherited. E. Generally, the static method is used frequently, and the dynamic method is used in a few ways. Static speed is fast, occupying memory. The dynamic speed is relatively slow, but the class is released immediately after the call, which can save memory. You can choose whether to use the dynamic method or static method as needed. F The static method modifies the state of the class, and the object modifies the state of each object. This is also an important difference between them. Class instantiation calls exist in the life cycle of the class, when the class is gone, the corresponding instance will be gone, and the corresponding method will be gone. If the static class is not, as long as you reference the static class namespace, it will always exist, know you quit the system. 6 alloc \ init and new A seldom use new in actual development, generally, [[className alloc] init] is used to create an object. The difference is that when alloc allocates memory, zone is used to allocate memory to the object, allocate the associated objects to an adjacent memory area, which consumes a small amount of money and increases the processing speed of the program. C. Why is new not recommended? If new is used, the initialization method is fixed and only init can be called. What if you want to call initXXX? You can use the default init method to complete initialization. You can use other custom initialization methods by using alloc. 7 @ property @ synthesize A is used to simplify the SET of attribute variables. The GETB simple Syntax B1 @ property data type variable name is in the. h file; B2 @ synthesize variable name; C complex syntax

 

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.