IOS Learning Note 2015-03-18

Source: Internet
Author: User

objective--c keyword 1 KVC dynamic value, dynamic value, similar to rain in Java reflection, and private can still set and get 22 function 1 retain to object reference counter + Release to object reference counter-dealloc pin Destroy the object, when the object causes the counter to be O, the method is automatically called, 4 autorelease deferred object 5 Setvalue:forkey Set object property value (Simple) 6 Setvalue:forkeypath Set object property value (complex) 7 Valueforkey: Get object property value (Simple) 8 Valueforkeypath Get object property value (complex) 9 Floatvalue string to Flaot type ten intvalue string to Nsinteger type three Rules 1 reference counter A object Memory Management B There is no garbage automatic recovery mechanism in OC, so need to manually recycle, so use this rule, in fact, in OBJC memory management is dependent on the object reference counter to do: in OBJC each object inside each has a corresponding integer (retaincount), called " Reference counter ", when an object is created after its reference counter is 1, when calling the object's alloc, retain, new, copy method after the reference counter automatically add 1 on the original base (OBJC call an object method is to send a message to this object), When the release method of this object is called, its reference counter is reduced by 1, and if an object has a reference counter of 0, the system automatically calls the object's Dealloc method to destroy the object. C Memory Release principle who created, who released D Close Project Arc Project Properties-build settings--Search "garbage" find Objective-c Automatic Reference counting set to No. 2 Automatic release Pool A There is also a mechanism for automatic memory release in OBJC called "Auto Reference count" (or "auto-free Pool"), unlike C #, Java, which is only a semi-automatic mechanism, and some operations need to be set manually. Automatic memory release declares a block of code using the @autoreleasepool keyword, and if an object calls the Autorelase method at initialization time, when the code block executes, Objects that have called the Autorelease method in a block will automatically call the release method once. This has the effect of automatic release, while the object's destruction process is also delayed (unified call Releasemethod) The B-autorelease method does not alter the object's reference counter, but simply places the object in the auto-release pool; the C auto-release pool is essentially the release method of invoking an object when the auto-release pool is destroyed, not necessarily destroying the object (for example, if a reference counter for an object > 1 can not be destroyed at this time); D because the automatic release of the pool finally unified destruction of objects, so if an operation compared to occupy memory (more objects or objects occupy a lot of resources), it is best not to put in the automatic release pool or consider to be put into multiple auto-release pool; The static methods in class library in E OBJC , the Autorelease method has been called internally, and the operation method of the 3 key value encoding KVCA KVC is provided by the Nskeyvaluecoding protocol, and NSObject implements the protocol, meaning that almost all the objects in OBJC support KVC operation b Dynamic settings: SetValue: Property value Forkey: Property name (for simple Path), SetValue: Property value Forkeypath: Property path (for compound path, for example, person has an account type property, So Person.account is a composite property) C Dynamic read: Valueforkey: Property name, Vamlueforkeypath: property name (for compound path) D KVC is relatively simple to use, but how does it find an attribute to read? Specific lookup rules (assuming that you want to use KVC to read a): I If the property is dynamically set, the first call to the Seta method, if not the method is the first to consider the search member variable _a, if it still does not exist then the search member variable A, if the last still did not search to call this class Setva Lue:forundefinedkey: Method (Note that the search process regardless of whether these methods, member variables are private or public can be set correctly); If it is a dynamic read property, the call to a method (the getter method of property a) is preferred. If there is no search, then the member variable _a is searched first, and if it does not exist then the member variable A is searched, and if it is not found then the valueforundefinedkey of the class is called: Method (Note that the search process regardless of these methods,    Whether the member variables are private or public can be read correctly); I-E can be dynamically set, dynamically, regardless of the object's member variable being private or public

IOS Learning Note 2015-03-18

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.