"Good Programmer's note sharing" obj-c analysis of the wrong problem

Source: Internet
Author: User

Due to the wrong click on the submission can not be entered, so can only write a small part of the beginning of the obj-c is not clear the topic (hope to improve, so that more conducive to learning).

1. The scope problem of variables in obj-c. The Obj-c language supports setting its scope with public , private, and protected . The default value is protected, which indicates that the variable can be accessed in this class and its derived classes. Public indicates that the class and its derived classes, as well as the outside of the class, can access the variable, which is less secure. Private means that only this class can access the variable, and it is worth proposing that if there is a private variable in the parent class, its subclasses cannot reference it. (This is not much different from C + +)

2, Category (categories). When you need to add some methods to a class that has already been defined and do not want to rewrite the class, you can select the class to do the method addition . Add a method to the class by categories, without creating a new subclass or modifying the source code of the class. When the class is loaded, the new method (method) becomes part of all class instances. It is important to note that the class cannot add an instance variable to the class, although the class can read an instance variable to extend the class, but the instance variable created by the class is not stored in the class. Second, the class can override the method in the class, but thereafter the user will no longer be able to invoke the method in the class, and the user should try to avoid overwriting the operation. A user can have many classes for a class that affects subclasses of that class. (I don't know if this is the same as the category in question)

3, agreement (protocol). Protocol is a unique way of inheriting in OC language. A protocol is a special list of methods that declares a series of methods without implementation. Protocols are not classes themselves, they simply define interfaces that other objects are responsible for implementing. When implementing a method of the protocol in its own class, the user's class is subject to this protocol. The method of the Protocol Declaration can be implemented by any one class. It is important to note that the Protocol does not have a parent class, and the protocol cannot define member variables. The two modifiers of the protocol @optional and @required, the method decorated by the modifier, which, on behalf of the class in which the Protocol is adopted, can be chosen not to implement the method, which represents the class that adopted the Protocol must implement the method. The default value for the protocol modifier is @required.

4, the allocation of memory, release

   Generate and hold methods such as Object Alloc/new/copy/mutablecopyd
Retain methods for holding objects
Releasing Object Release method
Deprecated object Dealloc method

This is a simple list of internal implementations to learn in the future (malloc free in ps:c)

"Good Programmer's note sharing" obj-c analysis of the wrong problem

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.