IOS Pen Questions

Source: Internet
Author: User

Ext.: http://blog.sina.com.cn/s/blog_b0c5954101014upb.html

1. Truncate the data in front and back of the ' | ' character in the string "20|http://www.621life.com", outputting them separately

Nsrange range = [responsestring rangeofstring:@ "| " ]; int location =*str1 =*str2 = [responsestring substringfromindex:location+1];

2. Get the project root path and under it create a directory named UserData.

 //  path  nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);        NSString  *documentsdirectory = [Paths Firstobject];        Nsfilemanager  *filemanager = [[Nsfilemanager Alloc]init]; NSString  *userdatapath = [nsstring stringwithformat:@ " %@/userdata   ,documentsdirectory];  if  (! false   Attributes:nil Error:nil]; }

3. In the method of an object: Self.name = "Object"; Is it different from name = "Object"?

Self.name = "Object" invokes the object's SetName () method,
Name = "Object" assigns an object directly to the Name property of the current object.
And Self.name This retaincount will add 1, and name will not.

4. When defining attributes, what happens when using copy,assign, and retain

Assign is used for simple data types such as Nsinteger,double,bool,retain and copy user objects;

Copy is used when a to point to an object, B also want to point to the same object, if you use Assign,a if released, then call B will crash, if copy, A and b each have their own memory, you can solve the problem.

Retain will add one to the counter, can also solve the problem of assign.

Additionally: Tomic and nonatomic are used to determine whether the getter and setter generated by the compiler are atomic operations. In a multithreaded environment, atomic operations are necessary, otherwise they may cause incorrect results.

5. What is the meaning of the keyword const? What about the modifier class? The role of static for classes? and the role of extern c.

The first two functions are the same, a is a constant integer number.

The third means that a is a pointer to a constant integer number (that is, the integer number is not modifiable, but the pointer can).

The fourth meaning a is a constant pointer to an integer number (that is, the integer number pointed to by the pointer can be modified, but the pointer is non-modifiable).

The last one means that a is a constant pointer to a constant number (that is, the integer number pointed to by the pointer is not modifiable and the pointer is not modifiable).

Conclusion:

The function of the keyword const is to convey very useful information to the person who is reading your code, and in fact, declaring a parameter as a constant is to tell the user the purpose of the parameter's application.

If you have spent a lot of time cleaning up the rubbish left by others, you will soon learn to thank for the extra information. (Of course, the rubbish that a const programmer seldom leaves

Someone else to clean it up. By giving the optimizer some additional information, using the keyword const may produce more compact code.


Proper use of the keyword const allows the compiler to naturally protect those parameters that you do not want to change, and prevent them from being unintentionally modified by the code. In short, this can reduce the bug

The appearance of.


(1) To prevent a variable from being changed, you can use the Const keyword. When defining this const variable, it is often necessary to initially
Start, because there will be no chance to change it again;
(2) For pointers, you can specify that the pointer itself is const, or that the data that the pointer refers to is const, or both
Fixed as const;
(3) In a function declaration, the const can modify the formal parameter, indicating that it is an input parameter, the value cannot be changed inside the function;
(4) For a class member function, if it is specified as a const type, it indicates that it is a constant function and cannot modify the member variables of the class;
(5) For a member function of a class, sometimes it is necessary to specify that its return value is a const type so that its return value is not "left value".

What does the keyword volatile mean? and gives three different examples.

A variable that is defined as volatile means that the variable may be unexpectedly changed so that the compiler does not assume the value of the variable.

Precisely, the optimizer must carefully re-read the value of the variable each time it uses the variable, rather than using the backup stored in the register.

Here are a few examples of volatile variables:

Hardware registers for parallel devices (e.g., status registers)
A non-automatic variable that is accessed in an interrupt service subroutine (non-automatic variables)
Variables shared by several tasks in multi-threaded applications


Can a parameter be either const or volatile? explain why.
Can a pointer be volatile? explain why.

Here's the answer:
Yes. An example is a read-only status register. It is volatile because it can be changed unexpectedly. It is const because the program should not attempt to modify it.
Yes. Although this is not very common. An example is when a service subroutine fixes a pointer that points to a buffer.

6. The role of the Static keyword:

(1) The function body static variable scope is the function body, different from the auto variable, the memory of the variable is only assigned once,
therefore, its value remains the last value at the next call;
(2) The static global variable within the module can be accessed by functions used within the module, but not by other functions outside the module;
(3) The static function within the module can only be called by other functions within this module, and the use of this function is limited to the declaration
within its module;
(4) A static member variable in a class is owned by the entire class and has only one copy of all objects of the class;
(5) The static member function in a class is owned by the entire class, which does not receive the this pointer, and therefore can only access static member variables of the class.

the role of extern "C"

(1) The function or variable defined by extern "C" is an extern type;
extern is a keyword that indicates the scope (visibility) of functions and global variables in the C/s + + language, which tells the compiler that
its declared functions and variables can be used in this module or in other modules.

(2) The variables and functions modified by extern "C" are compiled and connected in C language;
the customary method of extern "C"

(1) in C + + reference to the functions and variables in C, in the C language header file (assuming cExample.h), the need to enter
line the following processing:
extern "C" {
#include "cExample.h"
  }  
in the header file of the C language, the extern "C" declaration is not supported in the C language, except that its external function can only be specified as an extern type .
a compile syntax error occurs when the. c file contains extern "C".

(2) when referencing functions and variables in the C + + language, the header file of C + + needs to be added extern "C", but in C language does not
the header file that declares the extern "C" can be directly referenced, and only the extern "C" function defined in C + + should be declared as
extern type.

The role of the 7.readwrite,readonly,assign,retain,copy,nonatomic attribute

@property is a property access declaration that supports several properties within the extension:
1,getter=gettername,setter=settername, set the method name of setter and getter
2,readwrite,readonly, setting the available access level
The 2,assign,setter method is assigned directly, without any retain operation, in order to solve the problem of the original type and the circular reference
3,retain,setter method to release old values of parameters and then retain new values, all implementations are in this order (CC has relevant information)
4,copy,setter method copy operation, as with the retain process, the old value of release, and then copy the new object, Retaincount is 1.

This is the mechanism introduced to reduce dependency on the context.
5,nonatomic, non-atomic access, no synchronization, multi-threaded concurrent access improves performance. Note that if you do not add this property, the default is two access methods

are access to atomic transactions. The lock is added to the owning object instance level (as I understand ...).

33. What are the common methods of threading, how do you deal with multi-threaded, multi-threaded synchronization problems do you understand?
Thread creation in several ways, thread lock, Hibernate, Wake, unlock, exit,

Multithreading to consider synchronization problems, the way to solve the synchronization problem is to lock a resource, when a thread operation of this resource, other threads can not operate.


The system comes with the function of the thread pool (nsopertionqueue):

You can use nsopertionqueue wherever you need to start multiple threads, and objects that are added to Nsopertionqueue need to inherit nsopertion. Nsopertionqueue initiates a separate thread within the system to execute the main method of the object being added.

The common place is to download pictures and files with Nsoprationqueue. If you're creating a thread pool yourself, it's just a matter of starting multiple threads,

Put these thread objects into a large array, and if you need to start the thread, look for idle threads from the array.

The biggest challenge of managing the thread pool yourself is not to handle the callback management of the threading method when the user jumps across multiple interfaces after starting multiple threads.

And Nsopertionqueue can deal with him very well.

34.init and Initwithobject differences (syntax)?

Objects created by Init do not have automatic release

35. What is the method you use to connect to the server, and if the network is out of the question during the request?
After the nsurlconnection is connected, there is a series of delegate methods to accept the response and data from the server.

which accepts the corresponding method to get back the server to return the data is how large, the method of receiving data is repeatedly used to continuously accept the server data,

If there is a problem with the network, a method will be called to let you do the related processing.


36. Have you ever used JSON parsing, and how do they deal with the bottom layer, you know?


The use of JSON parsing, using the framework of the use of simple introduction:

The underlying principle iterates through the characters in the string, and ultimately differentiates them according to the special characters specified in the format, such as the {} number, [], and: number,

The {} number is the beginning of a dictionary, and the [] number is the beginning of an array: The number is the watershed of the dictionary's keys and values, and ultimately the JSON data into a dictionary.

The value in the dictionary may be a dictionary, an array, or a string.

What is the principle of 37.xml parsing, and have you used other analytic methods?

Nsxmlparser, other parsing methods have custom binary parsing, that is, by byte to parse, telephone talks is so,

It can also be data that is concatenated between strings with special symbols that can be segmented into the data used by special symbols.

38. What is the agreement and what role does it have?


The protocol is much like the interface in Java, after a class implements the protocol, it must implement the @require method stipulated in the Protocol, such as a Class A, a class B all implement a "protocol",

Both the object of this class A and the object of B can be assigned to the type variables of this protocol, such as id< protocol > variable name = Object of Class A or Class B,

The variable then accomplishes an object that can point to several different classes and invokes the implementation protocol in the object.

39. What is the role of the category?
The use of the category. Category has three major functions,

1. The method that would otherwise be required to be declared in. h is declared in the. m file, which is achieved by making the method non-public.

2. It is easy to extend the class, even the system classes can be easily extended to maintain the original structure of the code is not affected.

3. Categories can be written into different. h or. m files, which can be easily viewed by spreading the code to a place where the extended functionality of the category is to be associated.

40. What is the function of the thread callback main thread method?
[Self Performselectoronmainthread: @selector (BUTTONGO2) Withobject:nil Waituntildone:yes];
[Self performselector: @selector (BUTTONGO2) onthread:[nsthread Mainthread] Withobject:nil Waituntildone:yes];
It is often used when the UI control needs to be refreshed immediately.


41.iphone Reader, if you want to read a text file, how do you deal with the coding problem? Another file like PDF format, how do you read it.?


In the iphone reader, you can read the PDF format directly from the UIWebView control, or from the Internet to a lot of direct read PDF code.

Get the data directly from the PDF.

Complex table Animations
-(void) Insertrowsatindexpaths: (Nsarray *) indexpaths withrowanimation: (uitableviewrowanimation) animation; -(void) Deleterowsatindexpaths: (Nsarray *) indexpaths withrowanimation: (uitableviewrowanimation) animation;
-(void) Reloadrowsatindexpaths: (Nsarray *) indexpaths withrowanimation: (uitableviewrowanimation) animation;

42. How do you perform memory leak detection when you are developing a large project?
You can run---start with the Performance tool in Xcode with a leaks tool in the instruments.

After starting the tool, run the project, the tool can show the memory leaks, double-click to find the source location, can help with memory leak processing.

43. When you are developing an iphone, what are the values that are passed between view and view?

Press stack.

44. What are the methods for moving an object from one point in the interface to another?
Four different ways: 1. BeginAnimation

2. Threads

3. Nstimer

4. Layer Animation (PATH)


45. What encryption methods do you know?
Base64, MD5, circulation right shift and so on.

46. Map Positioning

Cllocationmanager position Manager uses the core location framework to determine the location of the iphone (GPS, cellular base station triangulation, WPS three ways)

Mkmapview provides an implantable map interface that allows us to display and manipulate the map in the app. In general, we can specify a display area, put some markers on it, and can cover some layers on top.

Mkmapview relies on Google Maps for services such as Google Earth API, so there's a Google word in the bottom-left corner of the map.

47. Open the URL

[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "tel://8004664411"]];mailto://sms://

HTTP network communication

ASIHTTPRequest is an open source project that is done directly on Cfnetwork: An API that provides direct submission (HTTP POST) files, asynchronous requests and queues, automatic management of uploads and downloads queue managers, asiformdatarequest for uploading files, Picture data.

49. Image View

Uiimagepickercontroller can get pictures from albums, cameras, and film.

50. For image serialization

Nscoding Encodewithcoder Initwithcoder

Nskeyedunarchiver Nskeyedarchiver

51. Various Picker

Uidatepicker Uipickerview

52. Movie Playback

MPMoviePlayerController

Music playback

Mpmusicplayercontroller

53. Threads?

A. Thread creation and usage rules?

Answer: Nsthread

Three different methods

-(ID) init; Designated initializer

-(ID) Initwithtarget: (ID) Target selector: (SEL) Selector object: (ID) argument;

+ (void) Detachnewthreadselector: (SEL) Aselector totarget: (ID) atarget withobject: (ID) anargument

-(void) start;

B. Main sub-threads

A: Start the sub-thread, mentioned above! Add to main thread method performselector!

Add to main thread adddata () is the main thread method! method to invoke the main thread only after adding to the main thread

[Target performselector: @selector (addData:) onthread:[nsthread Mainthread] Withobject:item Waituntildone:yes];

[Target adddata:item];//does not add to the main thread after calling the main thread method! It's going to shoot!

C. Thread Lock

Answer: Nscondition

Method:

[Thread lock];//plus lock

Sleep (n);//thread hibernation

[Thread singnal];//equivalent to notifications, threads start

[Thread unlock];//Unlock

[Thread exit];//thread exit

54. Various sorting algorithms?

Hill sort, quick sort, bubble sort,

55. Communication underlying principle

Answer: OSI seven layer model

7 Application layer: FTP,SMTP,HTTP,TELNET,TFTP (through various protocols, eventually packaged into TCP packets, sent to the network!) )

6 Presentation layer:

5 Session Layer:

4 Transport layer: TCP UDP

3 Network layer: IP,ICMP,IGRP,EIGRP,OSPF,ARP

2 Data Link layer: STP,VT

1 Physical Layer:

56. Why are the delegate properties of many built-in classes such as Uitableviewcontroller assign rather than retain?

For:

can cause circular references

All reference counting systems have problems with cyclic applications. For example, the following reference relationship:

* Object A was created and referenced to object B.

* Object B was created and referenced to object C.

* Object C was created and referenced to object B.

At this time, the reference counts for B and C are 2 and 1, respectively.

When a no longer uses B, the call release releases the ownership of B, because C also references B, so the reference count for B is 1,b and will not be freed.

B is not released, the reference count of C is 1,c and will not be released. From then on, B and C remain in memory forever.

In this case, the circular reference must be interrupted and the reference relationship maintained through other rules. Our common delegate is often the property of the assign way, not the retain way,

The assignment does not increase the reference count, which is to prevent unnecessary circular references being generated on both sides of the delegation.

If a Uitableviewcontroller object a acquires ownership of UITableView object B through retain, the delegate of this UITableView object B is a,

If this delegate is retain way, there is basically no chance of releasing the two objects. You should also be aware of this when designing your delegate model.

57. What is the retain count for the person object after each of the following lines of code is executed?

Person *person = [[Person alloc] init]; Count 1

[Person retain]; Retain Count 2

[Person Release];retain Count 1

[Person Release];retain count = 0

58. Inside the method of an object:

Self.name = "Object";

And

Name = "Object"

What's the difference?

A: Self.name = "Object" invokes the object's SetName () method, which causes object reference count plus 1,name = "Object" directly assigns an object to the Name property of the current object, and the reference count does not increase.


What is the function of 59.readwrite,readonly,assign,retain,copy,nonatomic property?

@property is a property access statement that supports several properties within the extension:? 1,getter=gettername,setter=settername, set the method name for setter and getter? 2,readwrite,readonly , set the available access level?

The 3,assign,setter method assigns values directly, does not perform any retain operation, in order to solve the original type and the circular reference problem? 4,retain,setter method to release the old value of the parameter and then retain the new value, all implementations are this order ( Information on cc)?

5,copy,setter method copy operation, as with the retain process, the old value of release, and then copy the new object, Retaincount is 1. This is the mechanism introduced to reduce dependency on the context.

6,nonatomic, non-atomic access, no synchronization, multi-threaded concurrent access improves performance. Note that if you do not add this property, the default is two access methods are atomic transaction access. The lock is added to the owning object instance level (as I understand ...).

7, @synthesize xxx; To implement the actual code



60.1.main ()

{

int a[5]={1,2,3,4,5};

int *ptr= (int *) (&a+1);

printf ("%d,%d", * (a+1), * (ptr-1));

}

Answer: 2,5

* (a+1) is a[1],* (ptr-1) is a[4], the result of the implementation is 2,5
&a+1 is not the first address +1, the system will assume that the offset of an array of a, is offset by the size of an array (this example is 5 int)
int *ptr= (int *) (&a+1);
Then PTR is actually & (a[5]), i.e. a+5
The reasons are as follows:

&a is an array pointer whose type is int (*) [5];
and the pointer plus 1 to add a certain value according to the pointer type, different types of pointer +1 after the increase in size.
A is an int array pointer of length 5, so add 5*sizeof (int)
So ptr is actually a[5]
However, PRT is not the same as (&a+1) type (this is important)
So prt-1 will only subtract sizeof (int*)

A,&a's address is the same, but it doesn't mean the same thing.
A is the address of the first address of the array, which is a[0], &a is the first address of the object (array),
A+1 is the address of the next element of the array, that is, a[1],&a+1 is the address of the next object, or A[5].

IOS Pen Questions

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.