IOS Interview title: OC Basic Concept questions < continuation >

Source: Internet
Author: User

first, how to determine the method name of a method
Remove the minus sign, plus sign, remove the return value, remove the parameter type, remove the parameter, and the rest is the method name.

Second, the ID points to any object type and can be used assign,copy,retain, as needed

Thirdly, when did the Autorelease release?
Release when encountering Autoreleasepool (you can put several of the same variables in a few different dominant)

The method of the protocol, by default, is @required

What are the features of the dictionary collection?
A dictionary is a saved element in the form of a key-value pair
Only objects can be stored and basic data types cannot be stored

Six, how to define a class?
The interface section of a class contains instance variables, properties, and methods
You can put both the Declaration and the implementation in the. h file
A pair of files (Person.h person.m) can define multiple classes
Classes are more abstract, objects are more specific

VII, what is a category?
Class can be a class without source code, add methods
The method in the class is the same as the method level in the original class.

To rewrite the parent method to a subclass with inheritance

Ninth, what is an object?
Object is an instance of a class, such as President Barack Obama

Tenth, the properties of the property,

For details, please click on the link below

Properties of the OC property



11th, do not tune yourself within the set method, and you will fall into a dead loop


12th, the difference between a mutable string and an immutable string
nsmutablestring * str = [[nsmutablestring alloc]initwithformat:@ "123"];
NSLog (@ "str =%p", str);
[Str appendformat:@ "456"];
NSLog (@ "str =%p", str);
The address printed above two times is the same

13th, a dictionary key is unique, so the dictionary has a function of the weight, print the dictionary, the left is key, the right is value

14th, you cannot use an instance variable in a class method

15th, Dealloc note (with system automatic call)
Open Arc can't write [Super Dealloc] Method
OC cannot be overloaded (same as method name, parameter is different), can only be overridden,

16th, the Singleton method is only for the purpose of obtaining a unique instance, usually without parameters in the method
A singleton is equivalent to a global variable and cannot be released.
such as user login, the user information written in a single case

17th, the initial function is to assign the initial value to the variable

18th, @package

The @package (frame level) scope is between private and public and can be accessed directly from the variable name as long as it is in the same frame.


19th, queue advanced first out, stack advanced after

20th, dynamic binding
NSString * Testobject = [[NSData Alloc]init]
Compile-time is nsstring type (not detected)

Runtime is NSData type (detection)

Here is a rough, specific OC dynamic characteristics, please click the link below

In-depth objective-c dynamic characteristics


21st, when block modifies an external variable, it is modified with __block

22nd, why use assign instead of retain when delegate or protocol apply for attributes?

The Declaration of the Agreement, with the Assign attribute, avoids the circular reference, please click below for more information.

Why use assign instead of retain when delegate or protocol apply for attributes?

Common methods of traversal in iOS


The purpose of the traversal is to get an object in the collection or to perform an operation, so that the method that satisfies the condition can be an alternative:
Classic for Loop
for in
Makeobjectsperformselector
KVC Set operator
Enumerateobjectsusingblock
enumerateobjectswithoptions (nsenumerationconcurrent)
dispatch_apply

24th, the property is the method is not a variable category inside is the method does not add the variable

25th, see the traversal of the constructor, to think of Autoreleasepool, sometimes the convenience of the constructor is often a memory leak error


26th, the protocol is a list of methods that are shared by multiple classes, and the methods listed in the Protocol are not implemented in a corresponding way, and there are others to implement
The property declaration of the Protocol is used with the Assign attribute because the memory cannot be freed by preventing references to each other between the object and other proxy objects


27th, categories, extensions, agreements, differences in inheritance
Category: The class can not be learned, without changing the original code in the case of adding new methods, can only add, cannot delete the original method, but cannot add the instance variable

Extension: Extension You can add instance variables and methods at the same time, and the methods you add must be implemented and can be treated as a private class

Protocol: A protocol is a list of methods that are shared by multiple classes, and the methods listed in the protocol do not have a corresponding implementation

Inheritance: Not only can you add instance variables and methods, but you can also override the methods of the original class

28th, when Autorelease no Autoreleasepool
Because the convenience constructor produces objects that cannot be freed if they are not autoreleasepool, the resulting objects will become more and more when the loop value is too large and the objects used cannot free up memory consumption. Severely affects performance so use Atutoreleasepool in the For loop, freeing memory to avoid memory leaks.

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.