IOS Interview Summary

Source: Internet
Author: User

This period of time has been busy interviewing to find a job, the process of the interview exposed some of their problems, or the foundation is not solid, although did three years of iOS development, but only the coding and architecture can also, the basics of things are not know, too should not, so determined to take the iOS base of things to fill a supplement, Here is a list of interview questions (a total reference).

1. Why use weak and assgin to decorate delegate? Why do you use strong or retain to cause circular references?

(1) Assgin is generally used in non-arc to modify the Delegate,weak is used in arc.

(2) weak will be automatically set to nil when delegate does not use the release, to prevent the dangling pointer.

(3) If using strong or retain to modify the delegate will cause a circular reference, the reason is controller A created in controller B's delegate=a, If you use retain or strong to modify a, a to release, because B has a reference to a, so a will not be released , and the same B will not be released, which causes a circular reference.


2. How do Core Foundation objects and Object-c objects translate? (illustrated by Cfstringref and NSString)

(1) In the non-ARC case, the two as long as forced conversion can be, such as: cfstringref str1 = (cfstringref) str2; (str2 for NSString objects )

nsstring *STR3 = (NSString *) STR4; (STR4 for cfstringref)

  (2) in the case of Arc, a __bridge conversion is required, specifically Span style= "font-size:18px" >cfstringref str1 =  ( __bridge Span class= "S3" style= "font-size:18px" >cfstringref ) str2 < Span style= "font-size:18px" > ( STR2 for nsstring object nsstring *str3 = (__bridge nsstring *) STR4; ( STR4 is cfstringref large security, which does not solve the problem of ownership of managed assignment objects, which can cause dangling pointers.

(3) general use__bridge_retained and__bridge_transfer to make conversions, such as:NSString*str2 = (__bridge_transfer NSString*) Str3; (str3 is a cfstringref object ); CfstringrefSTR4 = (__bridge_retainedCfstringref) str1; (str1 is a NSString object ), theobject held by the __bridge_transfer variable is released after the variable is assigned to the conversion target variable up.

(4)__bridge_retained and __bridge_transfer can be used respectively Cfbridgingretain and Cfbridgingrelease to replace


3. What happens when a memory warning is encountered?

(1) First analysis of the cause of the memory warning, there are two: one is the existence of memory leaks caused, one is loaded with too many resources.

(2) for the first case, tools are needed to analyze the causes of memory leaks.

(3) For the first case, the system calls uiapplication::d idreceivememorywarning-> Uiapplicationdelegate:: Applicationdidreceivememorywarning, and then calls all the current viewcontroller for processing so that some resources are freed.

< Span style= "White-space:pre" >   (4) IOS6 previous processing: DIDRECEIVEMEMORYWARNING-> viewdidunload, in viewdidunload release resources.

  (5) os 6 Abandoned the Viewdidunload method, which means that all we need ourselves in Operation in Didreceivememorywarning. Cleaning up some cached data and releasing the corresponding sub-view requires Determine if view is part of window, with if ( Self.isviewloaded&&! Self.View.window) {Self.view = nil};


4. What do nil, nil, NSNull, and null represent respectively? Under what circumstances to use

nil: A null pointer to an object

Nil: A null pointer to a class

null: null pointer to other types (such as base type, C type)

NSNull: Usually represents a null value in a collection


5. When will the object of Autorelease be released?

(1) Each application creates an auto-free pool of roots.

(2) When the created Autorelease object is no longer in use, it is freed by the most recent release pool, usually at the end of Nsrunloop, Releasing the contents of the pool automatically. ( for each runloop, the system implicitly creates a autorelease pool (which will naturally have multiple autorelease pool) so that all release The pool will form a stack like callstack, and at the end of each Runloop, the Autorelease pool at the top of the current stack will be destroyed so that each object in the pool will be release. )


6. What is the difference between Autoreleasepool call release and drain?

in a garbage collected environment, release does nothing. NSAutoreleasePool therefore provides a drain method that behaves in a reference-counted environment and calls release, but triggers collected in a garbage garbage environment Collection action.

7. Implement a NSString class?

+ (ID) stringwithcstring: (const char*) nullterminatedcstring            encoding: (nsstringencoding) encoding{  nsstring  *obj;  obj = [self allocwithzone:nsdefaultmalloczone ()];  obj = [obj initwithcstring:nullterminatedcstring encoding:encoding];  return autorelease (obj);


8. What is the difference between int and nsinteger?

Nsinteger Regardless of whether the device is 32-bit or 64-bit, it is an int in a 32-bit system and a long in a 64-bit system.


9. How to adapt the x64 bit system, how to upgrade the program developed from 32-bit to 64-bit?

Issues to be aware of:

(1). Update third-party libraries to support x64-bit systems.

(2). increase the architecture of arm64

(3) contains the assembly code, because 32-bit architecture and 64-bit architecture has its huge differences, it is impossible to mix code, specific case Analysis

(4) sizeof

(5) exchange of pointers and integers

(6)int and nsinteger distinguish, unsigned int and nsuinteger differ, must use Nsinteger and nsuinteger


IOS Interview Summary

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.