IOS study notes, ios2015-03-18

Source: Internet
Author: User

IOS study notes, ios2015-03-18

Objective -- C key word 1 KVC dynamic value setting, dynamic value, similar to reflection in java, in addition, you can also set and obtain the second function 2, the second function 1, and the retain to reference the counter + 12 release to the object to reference the Counter-13 dealloc to destroy the object. When the counter caused by the object is O, automatically call this method. 4 autorelease delays releasing objects. 5 setValue: forkey: Set object attribute values (simple) 6 setvalue: forkeyPath: Set object attribute values (complex) 7 valueForKey: Get object attribute values (simple) 8 valueForKeyPath get object attribute value (complex) 9 floatValue string to flaot type 10 intValue string to NSInteger Type 3 Rule 1 Reference Counter A Object Memory Management B there is no automatic garbage collection mechanism in OC, therefore, manual collection is required. Therefore, this rule is used in ObjC. In ObjC, each object has a corresponding INTEGER (retainCount), which is called "reference counter ", when an object is created, its reference counter is 1, when the alloc, retain, new, and copy methods of this object are called, the reference counter automatically adds 1 to the original base (the method for calling an object in ObjC is to send a message to this object ), when the release method of this object is called, its reference counter minus 1. If the reference counter of an object is 0, the system will automatically call the dealloc method of this object to destroy this object. C. The principle of memory release who creates and who releases D. Close project ARC project properties-Build Settings -- search for "garbage" and find Objective-C Automatic Reference Counting and set it to No. 2. automatic release pool A also has an automatic memory release mechanism in ObjC called "automatic reference count" (or "automatic release pool"). Unlike C # and Java, this is only a semi-automatic mechanism, and some operations still need to be set manually. The @ autoreleasepool keyword is used to declare a code block for automatic memory release. If an object calls the autorelase method during initialization, after the code block is executed, objects that call the autorelease method in a block will automatically call the release method once. In this way, the object is automatically released, and the destruction process of the object is also delayed (the release method is called uniformly). The B autorelease method does not change the reference counter of the object, only put this object in the automatic release pool; the essence of C automatic release pool is to call the release method of the object after the automatic release pool is destroyed, objects may not be destroyed. (For example, if the reference counter of an object is greater than 1, objects cannot be destroyed, therefore, if an operation occupies more memory (more objects or more resources are occupied by objects), it is best not to place the operation in the Auto Release pool or consider putting it in multiple Auto Release pools; the static methods in the E ObjC class library generally do not need to be manually released, and the autorelease method has been called internally. The 3 key-value encoding kvca kvc operation method is provided by the NSKeyValueCoding protocol, NSObject implements this Protocol. That is to say, almost all objects in ObjC support the dynamic setting of KVC operation B: setValue: attribute value forKey: attribute name (for simplicity ). Single Path), setValue: attribute value forKeyPath: attribute path (used for compound paths. For example, if Person has an Account-type attribute, then person. account is a composite attribute. C. dynamic reading: valueForKey: attribute name, vamlueForKeyPath: attribute name (for composite path) D. KVC is easy to use, but how does it find an attribute for reading? Specific Search rules (assuming that KVC is used to read a): If I dynamically set attributes, the setA method is preferred, if this method is not available, search for member Variable _ a first. If it still does not exist, search for member variable a. If it still does not exist, the setValue: forUndefinedKey of this class will be called: method (note that these methods, whether the member variables are private or public, can be correctly set during the search process); I if it is a dynamic read attribute, the call of method a (the getter method of attribute a) is preferred. If no value is found, the member Variable _ a is preferentially searched. If no value exists, the member variable a is searched, if no value is found, the valueforUndefinedKey of this class will be called: method (note that the methods, member variables are private or public in the search process can be correctly read ); I E whether the object's member variables are private or public, they can also be dynamically set and the dynamic value

 

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.