FAQ (2)

Source: Internet
Author: User

6. Use obj-C to write a bubble sort.

-(Void) mysort :( nsmutablearray *) mutarray {ID tmpobj = nil; unsigned long flag = mutarray. count-1; // flag: the largest flag while (flag> 0) {int K = flag; flag = 0; For (Int J = 0; j <K; j ++) {int order = nsorderedascending; // or nsordereddescendingif ([[mutarray [J] description] compare: [mutarray [J + 1] description] =-order) {tmpobj = mutarray [J]; mutarray [J] = mutarray [J + 1]; mutarray [J + 1] = tmpobj; flag = J ;}}}}


Extended: C language Bubble Sorting: (1) the Bubble Method sorts elements in one-dimensional arrays void sort (INT arr [], int arr_len)
{

For (INT I = 0; I <arr_len-1; I ++) // outer loop {

For (Int J = 0; j <arr_len-1-i; j ++) // the number of times a trip is made by J {

If (ARR [J]> arr [J + 1]) {

Int temp = 0; temp = arr [J]; arr [J] = arr [J + 1]; arr [J + 1] = temp;

}}

}}

(2) Sort strings with pointer Arrays
Void sort_a (char * name [], int N ){

Char * temp;
For (INT I = 0; I <n-1; I ++ ){

For (Int J = 0; j <n-1-i; j ++ ){

If (strcmp (name [J], name [J + 1])> 0)

{
Temp = Name [J]; name [J] = Name [J + 1]; name [J + 1] = temp;

}}

}}

(3) Sort string Arrays
Void rang (char STR [] [20], int N ){

For (INT I = 0; I <n-1; I ++ ){

For (Int J = 0; j <n-1-i; j ++ ){

Int result = strcmp (STR [J], STR [J + 1]); If (result> = 0)
{

Char temp [20]; strcpy (temp, STR [J]); strcpy (STR [J], STR [J + 1]); strcpy (STR [J + 1], temp );

}}

}}

7. Your understanding of uiview, uiwindow, and calayer

Uiview: belongs to the uikit. Framework framework. It is responsible for rendering the content of the rectangular area, adding animations to the rectangular area, responding to the touch events of the area, layout and managing one or more sub-views.

Uiwindow: A Framework of the uikit. framework. It is a special type of uiview. Generally, only one uiwindow exists in a program, but multiple uiwindows can be created manually and added to the program.

Uiwindow mainly plays three roles in the program:

1. As a container, including all views to be displayed by the app

2. Send the touch message to the view and other

3. Work with uiviewcontroller to facilitate device Rotation

Calayer: It belongs to quartzcore. Framework and is used to draw content. It is used to display the content based on animation and uiview, and cannot process user events. Uiview and calayer are mutually dependent. uiview depends on the content provided by calayer, and calayer depends on uiview to display the drawn content in a container. Extended: uiviewcontroller: manages the maturity of a view. Each View Controller has its own view and is responsible for all transactions related to this view. It facilitates the management of sub-views in the view and communicates with the view. It detects device rotation and memory warnings. It is an accumulation of all view control classes and defines the basic functions of the controller.

Figure of uiresponder

8. Write a complete proxy, including declaration and implementation.
// Create
@ Protocol beforemarrieddelagate <nsobject> @ required

-(Void) docook :( nsstring *) foodname;-(void) dohomework;
@ Optional

-(Void) drivecar;

-(Void) makemoney; @ end

// Statement
@ Interface BOY: nsobject <beforemarrieddelagate>

-(Void) docook :( nsstring *) foodname;-(void) dohomework;-(void) makemoney;
// Implementation

@ Implementation boy

-(Void) docook :( nsstring *) foodname

{

Nslog (@ "cooking: % @! ", Foodname );

}

-(Void) dohomework

{

Nslog (@ "wash clothes today! ");

}

-(Void) makemoney

{

Nslog (@ "coding !! ");

}
@ End
9. What is the difference between JSON and XML analysis? What is the underlying Parsing Method of JSON and XML?

Differences:

(1) Readability: It is basically the same, and XML is more readable.

(2) Scalability: Both of them have good scalability.

(3) encoding difficulty: JSON encoding is relatively easy

(4) difficulty in decoding: the difficulty of decoding JSON is basically zero. For XML, child nodes and parent nodes must be considered.

(5) data volume: JSON is smaller than XML, and the transfer speed is faster.

(6) Data Interaction: The Interaction Between JSON and JavaScript is more convenient for parsing and processing, and better data interaction

(7) Data Description: XML is more descriptive about data.

(8) transmission speed: JSON is much faster than XML

Underlying principle of JSON: traverses characters in a string and distinguishes them based on special characters specified in the format, such as {}, [], and, {} is the beginning of a dictionary, and [] is the beginning of an array. The number is the watershed between the keys and values of the dictionary. In the end, JSON data is converted into a dictionary, the median value in a dictionary may be a dictionary, array, or string.

Underlying principle of XML: There are two common parsing methods for XML parsing: Dom parsing and sax parsing. Dom uses a tree structure to access XML documents, while sax uses an event model. . Dom parsing converts an XML document into a tree containing its content and can traverse the tree. When using the DOM parser, you need to process the entire XML file, so the performance and memory requirements are relatively high. When parsing XML documents, Sax can trigger a series of events. When a given tag is found, it can activate a callback method to tell the method that the tag has been found. The memory requirements of sax are usually relatively low, because it allows developers to decide the tag to be processed by themselves. Especially when developers only need to process part of the data contained in the document, the extension capability of Sax is better reflected.

Extended: differences between Sax and DOM:

1. The advantages of sax processing are very similar to those of streaming media. The analysis can start immediately, rather than waiting for all data to be processed. Because the application only checks data when reading data, it does not need to store the data in the memory. This is a huge advantage for large documents. In fact, the application does not even have to parse the entire document; it can stop parsing when a condition is met. In general, Sax is much faster than its replacement Dom. On the other hand, since the application does not store data in any way, it is impossible to use SAX to change the data or move back in the data stream.

2. Dom and generalized tree-based processing have several advantages. First, because the tree is persistent in the memory, you can modify it so that the application can change the data and structure. It can also navigate up and down the tree at any time, rather than one-time processing like sax. Dom is much easier to use. On the other hand, constructing such a tree in the memory involves a lot of overhead. It is not uncommon for large files to fully occupy the system memory capacity. In addition, creating a DOM tree may be a slow process.

3. Select Dom or sax, depending on the following factors:
Purpose of the application: If you plan to make changes to the data and output it as XML, Dom is the right choice in most cases. It doesn't mean that you can't change data by using sax, but the process is much more complicated, because you must copy the data instead of making changes to the data itself.
Data capacity: for large files, Sax is a better choice. How to use data: If only a small amount of data is used, it may be better to use SAX to extract the data to the application. On the other hand, if you know that you will reference a large amount of information that has been processed in the future, Sax may not be an appropriate choice.
Speed requirement: the sax implementation is usually faster than the DOM implementation.

It is important to remember that sax and Dom are not mutually exclusive. You can use Dom to create a sax event stream or a DOM tree. In fact, most Resolvers used to create the DOM tree actually use SAX to complete this task!

10. When is didreceivememorywarning of viewcontroller called? What is the default operation? When the program receives a memory warning, viewcontroller will receive this message: didreceivememorywarning starts from ios3.0. You do not need to reload this function and put the code for releasing the memory in viewdidunload. The default implementation of this function is: Check whether the controller can safely release its view. If the view can be released, this function releases the view and

Call viewdidunload. Reload this function to release other memory used in the controller. Remember to call the super implementation of this function to allow the parent class (usually uiviewcontroller) to release the view. If your viewcontroller saves the reference of the view sub-view, in earlier IOS versions, you should release these references in this function. In ios3.0 or later, you should release these references in viewdidunload.

FAQ (2)

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.