<span id="Label3"></p><p><p>first, Jane answers</p></p><p><p><span xml:lang="EN-US">1,<span xml:lang="EN-US">Objective-c class can inherit multiple? Can I use multiple protocols? </span></span></p></p><p><p>It is not possible to multiply inheritance, you can use multiple Protocols.</p></p><p><p><span xml:lang="EN-US">2,<span xml:lang="EN-US">#import和<span xml:lang="EN-US">#include的区别是什么? #<span xml:lang="EN-US"> <span xml:lang="EN-US">What's The difference between import<> and #import? </span></span></span></span></span></p></p><p><p><span xml:lang="EN-US"><span xml:lang="EN-US">#import能避免头文件被重复包含的问题<span xml:lang="EN-US">:</span> </span></span></p></p><p><p><span xml:lang="EN-US">1. In general, <span xml:lang="EN-US">when importing header files for Objective C <span xml:lang="EN-US">, use a #import, <span xml:lang="EN-US">#include when containing C/D + + header files <span xml:lang="EN-US">. </span></span></span></span></span></p></p><p><p>Use <span xml:lang="EN-US">include to pay attention to the issue of repeated references:</span></p></p><p><p><span xml:lang="EN-US">Class a,<span xml:lang="EN-US">Class B all refer to <span xml:lang="EN-US">class C, and<span xml:lang="EN-US">class D will quote a <span xml:lang="EN-US">duplicate reference if it references Class A and <span xml:lang="EN-US">class B. </span></span></span></span></span></span></p></p><p><p><span xml:lang="EN-US">2. #import determine that a file can only be imported once, so that you do not have problems with recursive Inclusion.</span></p></p><p><p>so,<span xml:lang="EN-US">#import比起<span xml:lang="EN-US">#include的好处就是它避免了重复引用的问题. So in <span xml:lang="EN-US">OC we basically use <span xml:lang="EN-US">import. </span></span></span></span></p></p><p><p><span xml:lang="EN-US"></span></p></p><p><p>#<span xml:lang="EN-US">import<> contains <span xml:lang="EN-US">classes in the iOS Framework class library,<span xml:lang="EN-US">#import "" contains the custom classes in the Project. </span></span></span></p></p><p><p><span xml:lang="EN-US">3<span xml:lang="EN-US">. What is category? How do you extend a class by inheriting good or class? Why? </span></span></p></p><p><p><span xml:lang="EN-US">Category is an item of Category. Use a good class, because the inheritance to meet the relationship of a <span xml:lang="EN-US">is a b, and the class only needs to meet a <span xml:lang="EN-US">has a B relationship, the limitations are smaller, you can extend the functionality of a class without defining subclasses, but also to separate the definition of the class in different source files <span xml:lang="EN-US">, with <span xml:lang="EN-US"> Category to rewrite the method of the class, only <span xml:lang="EN-US">valid for this category, does not affect the other classes and the original class Relationship. </span></span></span></span></span></span></p></p><p><p><span xml:lang="EN-US">4. What is extension? What is the role?</span></p></p><p><p><span xml:lang="EN-US">Extension (<span xml:lang="EN-US">Extension)<span xml:lang="EN-US">: Adds a class in the implementation file of its own class to declare a private method. </span></span></span></p></p><p><p><span xml:lang="EN-US">5. @protected of class instance (member) variables <span xml:lang="EN-US">, @private, What does @public declaration mean? </span></span></p></p><p><p><span xml:lang="EN-US">@protected: protected, The instance variable can only be accessed within the class and its subclasses and cannot be accessed within other Classes.</span></p></p><p><p><span xml:lang="EN-US">@private: private, The instance variable can only be accessed within that class and cannot be accessed within other Classes.</span></p></p><p><p><span xml:lang="EN-US">@public: common, This instance variable can be accessed by anyone.</span></p></p><p><p><span xml:lang="EN-US">6.<span xml:lang="EN-US">What are the characteristics of an ID declared object? </span></span></p></p><p><p><span xml:lang="EN-US">Ø No <span xml:lang="EN-US">* Number</span></span></p></p><p><p><span xml:lang="EN-US">Ø Dynamic Data type</span></p></p><p><p><span xml:lang="EN-US">Ø can point to objects of any class <span xml:lang="EN-US">(set to <span xml:lang="EN-US">Nil) without concern for their specific type</span> </span></span></p></p><p><p><span xml:lang="EN-US">Ø check its specific type at run time</span></p></p><p><p><span xml:lang="EN-US">Ø can send any (existing) message to it</span></p></p><p><p><span xml:lang="EN-US">7. What is a delegate? What are the attributes of the property declaration between the delegate and the principal <span xml:lang="EN-US">? Why? </span></span></p></p><p><p>Delegate: One object holds a reference to another object, and the referenced object implements a predetermined protocol that notifies the referenced object of changes in the reference Object.</p></p><p><p><span xml:lang="EN-US"></span></p></p><p><p><span xml:lang="EN-US">The property declaration properties of both the delegate and the principal are <span xml:lang="EN-US"> <span xml:lang="EN-US">assign and not <span xml:lang="EN-US">retain</span> </span> </span></span></p></p><p><p>To avoid memory leaks caused by circular references.</p></p><p><p>The problem of circular referencing is so understood:</p></p><p><p><span xml:lang="EN-US"><span xml:lang="EN-US">For example <span xml:lang="EN-US">, two classes of objects A and B are created in the main function, and the <span xml:lang="EN-US"> <span xml:lang="EN-US">reference count is now <span xml:lang="EN-US">1. Now let <span xml:lang="EN-US">A and <span xml:lang="EN-US">b reference each other <span xml:lang="EN-US">(a has a property is a <span xml:lang="EN-US">b object, The property description is <span xml:lang="EN-US">retain;<span xml:lang="EN-US">B has a property is <span xml:lang="EN-US">a object, the property description is <span xml:lang="EN-US">retain), and now the reference count of two objects has increased <span xml:lang="EN-US">1, all turned into <span xml:lang="EN-US">2. </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p></p><p><p><span xml:lang="EN-US">Now execute <span xml:lang="EN-US">[A release]; [B release]; At this point the main function of the created object <span xml:lang="EN-US">has freed itself of ownership of the object, but at this point <span xml:lang="EN-US"> <span xml:lang="EN-US">the reference count of A and B are still <span xml:lang="EN-US">1 because they reference each other. </span></span></span></span></span></span></p></p><p><p><span xml:lang="EN-US">At this point you find that <span xml:lang="EN-US">A and <span xml:lang="EN-US">B will not be released, because to release <span xml:lang="EN-US">a You must first release <span xml:lang="EN-US">b, and <span xml:lang="EN-US"> <span xml:lang="EN-US">then release A in the Dealloc method of B <span xml:lang="EN-US">. similarly, to release <span xml:lang="EN-US">b, you must first release <span xml:lang="EN-US">a, and <span xml:lang="EN-US"> <span xml:lang="EN-US">then release B in the Dealloc method of a <span xml:lang="EN-US">. So these two objects will always be in memory and not Released. This is called the circular reference Problem. </span></span></span></span></span></span></span></span></span></span></span></span></span></p></p><p><p><span xml:lang="EN-US">To solve this problem, the general method can set the referenced property to assign instead of <span xml:lang="EN-US"> <span xml:lang="EN-US">retain to handle it. </span></span></span></p></p><p><p><span xml:lang="EN-US">8. What is the difference between a shallow copy and a deep copy?</span></p></p><p><p><span xml:lang="EN-US">Shallow copy: copies only pointers to objects, not the reference object Itself.</span></p></p><p><p>Deep copy: copies the reference object Itself.</p></p><p><p>It means that I have an <span xml:lang="EN-US">a object, after copying a copy to get <span xml:lang="EN-US">a_copy object, for shallow copy,<span xml:lang="EN-US">A and <span xml:lang="EN-US">a_copy point to the same memory resource, copy is just a pointer, the object itself is a resource or only one copy, if we <span xml:lang="EN-US"> _copy performed the modification operation <span xml:lang="EN-US">, then found that <span xml:lang="EN-US">a reference to the object is also modified, which in fact violates our idea of copying Copies. Deep replication is a good understanding <span xml:lang="EN-US">that there are two independent objects in Memory. </span></span></span></span></span></span></span></span></p></p><p><p>Using a friend on the internet, the popular words will Be:</p></p><p><p>Shallow copy is like you and your shadow, you are finished, your shadow is finished</p></p><p><p>Deep replication is like you and your clones, you're screwed, your clones are Alive.</p></p><p><p><span xml:lang="EN-US">9. What are the several principles of memory management? by default, which keywords generate objects that need to be released manually? Which cases do not require manual release and will go directly to the Auto-release pool?</span></p></p><p><p><span xml:lang="EN-US">• When <span xml:lang="EN-US"><span xml:lang="EN-US">you create an object using the new, alloc, or <span xml:lang="EN-US">copy method, the object references a counter of <span xml:lang="EN-US">1. If you do not need to use the object, you can send <span xml:lang="EN-US">a release or <span xml:lang="EN-US">autorelease message to it, which is destroyed when it is finished using it. </span></span></span></span></span></span></span></p></p><p><p><span xml:lang="EN-US">• If you get an object by another method, you can assume that the object reference count is <span xml:lang="EN-US">1, and that it is set to <span xml:lang="EN-US">autorelease, you do not need to clean the object, if you do need to <span xml:lang="EN-US">retain this object, you need to use <span xml:lang="EN-US">the Release </span></span></span></span></span></p></p><p><p><span xml:lang="EN-US">• If you <span xml:lang="EN-US">retain an object, you need to <span xml:lang="EN-US">release or <span xml:lang="EN-US">autorelease the object, keeping the <span xml:lang="EN-US">retain method and the <span xml:lang="EN-US">release method using the same number of Times. </span></span></span></span></span></span></p></p><p><p><span xml:lang="EN-US"></span></p></p><p><p><span xml:lang="EN-US">objects generated using the new,<span xml:lang="EN-US">alloc,<span xml:lang="EN-US">copy keywords, and <span xml:lang="EN-US">retain objects need to be released Manually. Objects set to <span xml:lang="EN-US">autorelease do not need to be released manually and will go directly to the Auto-free Pool. </span></span></span></span></span></p></p><p><p><span xml:lang="EN-US"></span></p></p><p align="left"><p align="left"><span xml:lang="EN-US">10, how to implement a singleton model of the class, give ideas, do not write Code.</span></p></p><p align="left"><p align="left"><span xml:lang="EN-US">• You must first create a global instance that is typically stored in a global variable <span xml:lang="EN-US">that is set to <span xml:lang="EN-US">nil</span> </span></span></p></p><p align="left"><p align="left"><span xml:lang="EN-US">• Provide a factory method to access the global instance, check if the variable is <span xml:lang="EN-US">nil, <span xml:lang="EN-US">Create a new instance if nil, and then return to the global instance</span> </span></span></p></p><p align="left"><p align="left"><span xml:lang="EN-US">• Initialization of global variables is done in +allocwithzone: when the factory method is first called <span xml:lang="EN-US">, so you need to override this method to prevent new instances from being created in a standard <span xml:lang="EN-US">alloc way</span> </span></span></p></p><p align="left"><p align="left"><span xml:lang="EN-US">• To prevent <span xml:lang="EN-US">new instances from being obtained by the copy method, the <span xml:lang="EN-US">-copywithzone method</span> needs</span> to be implemented</span></p></p><p align="left"><p align="left"><span xml:lang="EN-US">• Simply return the object itself in this method, and the reference count does not need to be changed, since the object in singleton mode is not allowed to be destroyed, so it does not have to be preserved</span></p></p><p align="left"><p align="left"><span xml:lang="EN-US">• Because global instances are not allowed to be released, the <span xml:lang="EN-US">Retain,release,autorelease method needs to be rewritten</span></span></p></p><p><p><span xml:lang="EN-US">11.<span xml:lang="EN-US">What is the role of @class? </span></span></p></p><p><p><span xml:lang="EN-US">In a header file, it is generally only necessary to know the name of the referenced class. There is no need to know the entity variables and methods inside, so it is common to use @class in the header file <span xml:lang="EN-US">to declare that the name is the name of the class. In the implementation class, it is necessary to use the #import来包含这个被引用类的头文件 because it uses the entity variables and methods inside the reference class <span xml:lang="EN-US">. </span></span></span></p></p><p><p><span xml:lang="EN-US">• <span xml:lang="EN-US">@class's role is to tell the compiler that there is such a class, use it, no problem</span></span></p></p><p><p><span xml:lang="EN-US">• <span xml:lang="EN-US">@class can also solve the problem of cyclic dependencies, such as <span xml:lang="EN-US">A.h import <span xml:lang="EN-US">B.h, and <span xml:lang="EN-US">B.h import <span xml:lang="EN-US">A.h, Each header file compilation to let the object compile successfully before the line</span> </span> </span> </span> </span></span></p></p><p><p><span xml:lang="EN-US">• Use <span xml:lang="EN-US">@class to prevent this from happening</span></span></p></p><p><p><span xml:lang="EN-US">12<span xml:lang="EN-US">. What is KVC <span xml:lang="EN-US">? What are the characteristics of kvo? <span xml:lang="EN-US"> </span></span></span></span></p></p><p><p><span xml:lang="EN-US">• <span xml:lang="EN-US">KVC is a key-value encoding that allows you to read and set class properties by specifying a string identifier that represents the name of the property to be accessed</span></span></p></p><p><p><span xml:lang="EN-US">• <span xml:lang="EN-US">Kvo is a key-value observation, characterized by the use of key values to observe an observer who can register as an object, to be notified when a property of that object changes</span></span></p></p><p><p><span xml:lang="EN-US">13<span xml:lang="EN-US">. What is mvc? What are the characteristics? </span></span></p></p><p><p><span xml:lang="EN-US">– <span xml:lang="EN-US">MVC is a design pattern, consisting of models, views, and controller <span xml:lang="EN-US">3 Parts. </span></span></span></p></p><p><p><span xml:lang="EN-US">– Model: A class that holds application data, a class that handles business logic</span></p></p><p><p><span xml:lang="EN-US">– Views: windows, controls, and elements that other users can see and interact with</span></p></p><p><p><span xml:lang="EN-US">– Controller: class that will model and attempt to bind together to determine how user input is handled</span></p></p><p><p><span xml:lang="EN-US">14. When defining attributes, what is the use of <span xml:lang="EN-US">copy,<span xml:lang="EN-US">assign,<span xml:lang="EN-US">retain? </span></span></span></span></p></p><p><p>Use <span xml:lang="EN-US">assign: for underlying data types (<span xml:lang="EN-US">nsinteger,<span xml:lang="EN-US">cgfloat) and <span xml:lang="EN-US">C data types (<span xml:lang="EN-US">int, float, double, char, and so On)</span> </span> </span> </span> </span></p></p><p><p>Use <span xml:lang="EN-US">copy: when you want to get a copy of the source object without changing the contents of the source object, the <span xml:lang="EN-US">nsstring</span> </span></p></p><p><p>Use <span xml:lang="EN-US">retain: when you want to take ownership of the source object, the other <span xml:lang="EN-US">NSObject and its subclasses</span> </span></p></p><p><p>Objective-c/ios Development Questions (answer)</p></p></span>
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