IOS interview questions: basic concepts of OC

Source: Internet
Author: User

IOS interview questions: basic concepts of OC

1. What are classes and objects?


Class is the abstraction of a group of things with the same features and functions


Describes the features and behavior of an object.


Class is the abstract object of an object is an instance of a class.


2. Define classes in OC, create objects, and use objects.


Classes defined in OC are divided into interfaces and implementations.

Interface: Declares features and behaviors of a class.

Implementation part: implementation method, that is, class behavior implementation


To create an object, you need to allocate memory space and initialize it.


3. Declaration method, differentiated according to requirements: method declaration, method implementation, and method execution


4. Inheritance. All the characteristics of Inheritance


Subclass can inherit all declared methods of the parent class and instance variables other than private

The parent class cannot use the method and instance variable created by the subclass.


5. self and super


How to execute this class when self sends a message to an object

Super Method for sending a message to an object to execute the parent class


6. The initialization method will be customized as needed to write the complete implementation


Example:-(id) initWithName :( NSString *) name

Sex :( NSString *) sex

Age :( int) age

{

Self = [super init];

If (self)

{

Self. name = name;

Self. sex = sex;

_ Age = age

}

Return self;

}


7. What is the default visibility of instance variables and their respective characteristics?

How to operate the instance variables with default visibility outside the class.


@ Public

@ Protected (default)

@ Private


Outside the class, instance variables with default visibility can define the attributes of instance variables, and can declare and implement the setter and getter methods.


8. What is the setter and getter methods? How can I declare them?


SetName :( NSString *) name

Accessor-(NSString *) name;


9. Role of attributes. How to declare attributes and how to implement attributes (declaration and implementation of corresponding keywords)


Purpose: provide external access to automatically generate setter and getter Methods

@ Propert (attribute) return value or parameter type attribute name

@ Synthesize attribute name = instance variable


10. What are the three properties of an attribute? What does none of the features have? Use Cases and features


Read/write settings: readonly (read-only) readwrite (default)

Semantic settings: assign (the basic data type and object can be modified by default)

Retain (modifier)

Copy (the object to be modified must comply with <NSCopying> Protocol)

Atomicity: noatomic (multithreading security cannot be guaranteed)

Atomic (multi-thread security guaranteed by default)


11. Internal Implementation of the setter and getter methods of the attribute


Modify with retain

(Void) setName :( NSString *) name

{

If (_ name! = Name)

{

[_ Name release];

_ Name = [name retain];

}

}

(NSString *) name

{

Return [[_ name retain] autorelease];

}


12. Class extension. (Category extension protocol (one-to-one method). Proxy (method object in execution protocol)


Category: adds methods for classes without source code without instance variables.

Object Declaration: @ interface Class Name (Object Name)

@ End

Class implementation: @ implementation Class Name

@ End

Note: If a method of the category has the same priority as a method of the class, the method of the category has a higher priority.


Extention: (anonymous category) the "private" management method can contain instance variables in the. m file.

Declaration of Extension: @ interface Class Name ()

@ End

Note: The declared method in the extension must be implemented.


Protocol (protocol): There is no way to implement only the method declaration only. h file

The default keyword @ require must be implemented @ optionol.

Protocol Declaration: @ protocol name <NSobject>

Note: A class can accept multiple protocols, which are separated by commas (,) in <>. Multiple inheritance can be implemented using the protocol.


13. foundation (framework). NSString, NSArray, NSDictionary, and NSSet (Object content is different from each other). (differentiated between mutable and immutable, object creation, common methods, and class features)


NSString immutable (itself)

Naming rules

NSString

First, create initWithFormat or stringWithFormat
Second, evaluate the length of the string
Third, determine whether the string is equal to isw.tostring
Fourth, replace stringByReplacingOccurrenceOfString: withString:
Fifth, string comparison compare return value Enumeration
Sixth, String concatenation stringByAppendingFormat
Seventh, evaluate the character substringFromlndex
Eighth, query the string rangeOfString
Ninth, prefix, suffix hasPrefix hasSuffix
Tenth, uppercase uppercaseString

NSMutableString variable string

First, create a method that inherits from the parent class or use your own creation method. initWithCapacity
Second, add appendFormat :///////////
Third, delete deleteCharacterslnRange:
Fourth, change replaceCharacterslnRange:
Fifth, check insertString: atlndex ://///////////////



NSArray containers can only store unchangeable arrays of objects (Classes inherited from NSObject). They cannot be added, deleted, or modified,
First, create initWithObjects: arrayWithObjects:
Second, look at the element, objectAtIndex:
Third, number of arrays, [array count]

NSMutableArray variable string

First, add (ADD), addObject
Second, delete removeObjectAtIndex: removeObject removeAllObjects
Third, insert insertObject: atIndex:
Fourth, replaceObjectAtlndex: withObject:
Fifth, exchange exchangeObjectAtIndex :( destination string) withObjectAtIndex :( source string)


NSValue, NSNumber container, Conversion Function

NSValue converts struct to object
NSNumber converts the basic data type to an object.





14. Memory Management


Understanding of memory management:

Object ownership: Using retain alloc copy is the reference count of the object plus 1

Memory leakage: Only one block of memory is allocated and not released.

Excessive release: Multiple releases

Wild pointer: the pointer points to an object that does not exist.

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.