IOS interview notes (1)

Source: Internet
Author: User

I went to the XX Company IOS interview on Thursday.ProgramClerk, it took half a day to find a place. In a broken hotel, there was a small house and three office desks,

When I saw this scene, my heart was suddenly cool. The house was so hot that I sat there for a while and my back was wet.

I took an interview question for my manager. It was quite simple when I did it, but later I checked the information, as if I was not quite right in some places. The questions are as follows:

1: Does object-C have multi-inheritance? If not, what is the alternative?

My answer: No. Replace with Protocol

Online answer: All classes in cocoa are subclasses of nsobject. Multi-inheritance is used hereProtocol delegated proxyTo achieve

2: What is the static function?

My answer: static declaration. Declare a variable or method as static. When a static variable is instantiated for the first time, it allocates storage space. Static methods can be accessed without class instances.

Online answer:
(1) The static variable in the function body applies to this function body. Unlike the auto variable, the memory of this variable is allocated only once, therefore, this value is used to maintain the previous value during the next call.

(2) The static global variables in the module can be accessed by the functions used in the module, but cannot be accessed by other functions outside the module.

(3) The static function in the module can only be called by other functions in the module. The scope of use of this function is limited to the module that declares it.

(4) static member variables in the class belong to the entire class, and only one copy of all objects in the class is allowed.

(5) The static member function in the class belongs to the whole class. This function does not receive the this pointer, so it can only be a static member variable of the category.

3: # import and # include. @ Class represents what?

My answer: the difference is that # include can avoid the problem of circular reference. @ Class indicates that it identifies a class, which is # import in the. M file.

Online answer: @ class is generally used when an instance variable of this class needs to be declared in the header file. # import is still required in the M file.

The advantage of # import over # include is that it does not cause cross-compilation.

4: How is the memory management of Object-C managed?

My answer:
Reference count: When you use alloc to create a new instance or assign a value to a variable identified by retain, copy (or strong in Arc), the reference count of the instance or variable is plus one, when their reference count is 0, it is collected by GC.

Online answer: If you create an object by assigning and initializing an object (for example, [[myclass alloc] init]), you have this object and are responsible for releasing it. This rule also applies when using nsobject's convenient method new. If you copy an object and you have the Copied object, you must release the object. If you keep an object, you have part of it and need to release it when it is no longer needed.

5: What is the difference between frame and bounds in a view?

My answer: The View frame represents the position of the view in the parent class. View bounds represents the coordinates and length and width of the view.

Online answer:

Frame indicates the position and size of the view in the parent view coordinate system. (The reference point is the father's coordinate system)

Bounds indicates the position and size of the view in its own coordinate system. (The reference point is its own coordinate system)

6: How to Use ios4.1 or aboveCode(I have answered this question according to my understanding )?

My answer: when using non-arc Code in the ARC project, you need to set it in the compilation settings:-fno-objc-arc.

7: Write an example of delegated proxy.

. H file

 
@ ProtocolDelegate; @ Required-(Void) Dosomething; @ end @ interface delegatesimple<Delegate>@ End

. M file

# Import"Delegatesimple. h"@ Implementation delegatesimple-(Void) Dosomething {nslog (@"% @","This is implementation of the Protocol");} @ End

 

8: Use block to write a singleton instance.

+ (Class *) Sharedinstance {StaticClass *_ Singleton;StaticDispatch_once_t oncetoken; dispatch_once (& Oncetoken, ^{_ Singleton=[[Class alloc] init] ;});Return_ Singleton ;}

9: write out your frequently used multi-threaded calling methods.

-( Void  ) Downloadstringfromurl {nsurl * Url = [nsurl urlwithstring: [nsstring stringwithformart: @"  % @  " ,"  Www.xxxx.com  "  ]; Asihttprequest * Request = [Asihttprequest requestwithurl: url]; [Request setdelegate: Self]; [Request startasynchronous];}  # Pragma Mark-asihttprequest asynchronous request callback method -( Void ) Requestfinished :( asihttprequest * ) Request {nsstring * Responsestring = [Request responsestring]; nslog (  @"  % @  " , Responsestring );} -( Void  ) Requestfailed {nserror * Error = [Request Error]; nslog (  @"  % @  "  , Error );} 

 

After that, there was no person in the office who could take the lead. Then he called Mr. Wang, who was on a business trip in Nanjing and chatted with him for a long time. He seemed to have a great chat, because he had a bad signal in the subway, he had interrupted the call. Finally, he asked me about my salary. I thought the office environment was too bad and he deliberately said it was a little higher. He kept silence for a while and asked me to go back and wait for the message.

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.