IOS: summary

Source: Internet
Author: User

PS: Memory processing, cache processing, performance optimization, breakpoint continuation-afn, how to solve memory spike & resolution efficiency?

1. About SVN conflict

There are three options for resolving conflicts:

A, discard your updates, use svn revert (rollback), and then submit. In this way you do not need to use svn resolved (fix)

B. Discard your updates and use someone else's updates. Overwrite the target file with the newly acquired version, execute resolved filename and submit (select File-right-click-Resolve).

C, manual resolution: When a conflict occurs, manually update the target file after communicating with other users. The resolved filename is then executed to remove the conflict and finally commit.

How to reduce the complexity of conflict resolution:

1. When the document is edited and submitted as soon as possible, frequent commits/updates can reduce the probability of conflict occurrence and the complexity of resolving conflicts when they occur.

2, in the submission, write a clear message, convenient to find the reason for the user update, after all, with the passage of time, the reason for the original update may be forgotten

3, develop good usage habits, use SVN each time is first submitted, after the update. After opening every morning, first get the latest version from the repository. Documents that have already been edited must be submitted to the repository every day before they leave work.

2, JSON parsing, XML parsing, plist parsing

JSON parsing : self-bringing anti-sequence resolution (lightweight, slowly replacing XML) nsjsonserialization-- specifically converts JSON into a Foundation object and Class for the Foundation object to be converted to JSON

XML-refers to Extensible Markup Language (extensible Markup Language):

1,SAX parsing: 1. Open the document, 2. Start node, 3. Discover node contents, 4. End node, 5. End document-Apple uses Xmlparser to implement

2,DOM parsing: 1. reads an XML document into memory 2 in a tree structure at once. iOS does not support DOM parsing 3 by default. Use DOM parsing for very small XML data structures

plist parsing:

[Nspropertylistserialization propertylistwithdata:data options:0 format:null error:null];

Nspropertylistreadoptions

Ps:

Serialization: Before sending a request to the server, it is necessary to convert the OC object submitted to the server into binary data

Deserialization: After receiving data from the server, the binary data returned by the server needs to be converted to OC objects

Archive & Solve files:

-(void) Encodewithcoder: (Nscoder *) encoder

Encode an object into a binary data stream using an encoder, archive (persistent storage)

-(Instancetype) Initwithcoder: (Nscoder *) decoder

Use a decoder to decode the binary data stream stored on disk into an OC object

3. Comparison between AFN and ASI

-afn
1. Packages based on Nsurlconnection & Nsurlsession
2. Easy to use
3. Provides automatic serialization & deserialization support!

Advantages of AFN:
URL to pass a string directly
The data returned by the response can be semi-automatic deserialized (JSON can be automatically (AFN default JSON parsing), XML needs to be manually)
Code callback in the main thread, no need to care about inter-threading communication
Pass a parameter (parameters) in a dictionary without writing it in the URL (GET), or in the request body (POST)
Modify get requests and post requests based on API documentation, no need to focus on how to choose

[

1, the breakpoint continues to pass: 1. Gets the network file information, 2. Check local file information, 3. Download files based on offset location

NSString *range = [NSString stringwithformat:@ "bytes=%llu-", self.currentlength];

[Request Setvalue:range forhttpheaderfield:@ "range"];

2. Multithreading Analysis

3, segmented save (resolve memory Peak burst ):

Nsfilemanager: Do file copy, delete, check existence, create directory, delete directory, traverse directory ... Actions similar to those in the Finder

Nsfilehandle: Read and write binary data for a file

Tip : You can use MD5 to detect if the file is downloaded correctly!

Write data as a file stream: Nsstream is also a very important part of socket development.

Tip : Create a singleton to manage all of your global network sessions uniformly

]


-asi
1. Package Core Foundation based on Cfnetwork is the underlying C-language framework, and ASI's efficiency is well-
2. Very flexible to use, to provide programmers with a variety of possibilities and space for use!
* with Agent
* With block code
* Custom Monitoring method
* Custom Agent--developers can customize their own network management tools!

3. Hard to use
4. MRC, need to take into account the ARC & MRC mixed problems
5. The return content only provides binary data, or a string (the precondition is indeed a string!). )
The serialization and deserialization of ASI requires the programmer to do it himself!

[

ASI handles asynchronous requests through proxies, which notify the broker if a request succeeds or fails

agents are required to comply with the asihttprequestdelegate protocol

PS: Pass value via block callback, send POST request, file Upload & download, ASI data cache, cache a request, etc.

    • The fact that ASIHTTPRequest inherits from nsoperationmeans
    • Multiple asihttprequest can be placed in Nsoperationqueue , while managing multiple requests
    • you can set dependencies between requests  
    • Asiformdatarequest inherited from asihttprequest

Other uses:

1. Is there a network request in process now?

[asihttprequest isnetworkinuse];

2, when the request, whether to display the status bar network status (Turn circle)

[asihttprequest setshouldupdatenetworkactivityindicator:YES];

3. Whether to continue processing network requests while the app is running in the background

Request. shouldcontinuewhenappentersbackground = YES;

4. Set the number of retries after the request times out

Request. numberoftimestoretryontimeout = 2; // retry 2 times

]

4, Memory management:
Memory management needs and CPU utilization, to ensure reasonable memory usage space to improve the efficiency of program operation.
Resource Usage Priority: Network load, sandbox cache, system memory cache, database cache, and so on

5, run-time characteristics:
In OC is the Send message (message structure): code executed by the runtime is determined by the runtime environment, and the code that is executed by the language runtime of the function call is determined by the compiler. OC important work is done by runtime component, runtime component essence is a developer-written code related to the dynamic library, so long as the update runtime component can improve program performance.

Run-time mechanism:
1> runtime, runtime mechanism, it is a set of C language library

2> in fact, all of the OC code we wrote, eventually turned into the runtime library of things, such as the class into the runtime library inside the structure of the data type, the method into the runtime library in the C language function, peacetime adjustment method is turned into a objc_ Msgsend function (so that OC has a message sending mechanism)

3> Therefore, it can be said that runtime is OC's bottom-level implementation, is OC behind the actors 4> have the runtime library, what can do? The runtime library contains APIs related to classes, member variables, and methods, such as getting all the member variables in the class, adding member variables to the class dynamically, changing the method implementation of the class dynamically, adding new methods to the class dynamically, etc.

[ release required after object Properties are obtained at runtime ]

6. The difference between GCD and nsoperation:
GCD principle: The system has a thread pool for allocating and reclaiming threads, and programmers do not need to manage threads
Advanced features of GCD: Deferred execution after, one-time execution of once (singleton), scheduling group (for batch processing)
There are four combinations of GCD, nsoperation only global queues, asynchronous operations, and if you want to synchronize, you must use a dependency
Nsoperation Advanced: Maximum concurrency, control of thread count, optimized thread pauses, continuation, cancellation (GCD is too difficult to implement), dependency, allows asynchronous tasks to be executed synchronously

1. GCD is the underlying C-language API, while Nsoperationqueue and related objects are OBJC objects. In GCD, a block-composed task is executed in the queue, which is a lightweight data structure, and operation as an object gives us more choices;
2. In Nsoperationqueue, we can cancel any task that has been set up to be ready for execution at any time (of course, the task that has already started cannot be stopped), and GCD cannot stop the block that has joined the queue (but it does, but requires a lot of complex code);
3. Nsoperation can easily set dependencies, we can make one operation dependent on another operation, so that while two operation are in the same parallel queue, the former will be executed until the latter is finished;
4. We can apply KVO in Nsoperation, can listen to a operation whether the completion or cancellation, this can be more effective than gcd to control the background tasks we perform;
5. In nsoperation, we are able to set the priority of the nsoperation, enabling the task in the same parallel queue to be executed sequentially, whereas in GCD we can only distinguish the priority of different task queues, and if you want to differentiate the priority of a block task, Also need a lot of complex code;
6. We are able to inherit from the nsoperation, adding member variables and member methods on top of it, increasing the reusability of the entire code, which is more flexible than simply queuing the block task into the execution queue, and can add more self-customizing functionality on top of it.
7. GCD is a strict queue, FIFO fifo;nsoperation can change the priority (or service quality) to alter the order of execution

Nsoperation Advanced: Maximum concurrency, control the number of threads, optimize thread suspend, resume, Cancel function (GCD is too difficult to implement, can use KVO), dependency, can let asynchronous task synchronous execution

7. About Sdwebimage Cache

Sdwebimage cache processing must be delve into, more complex, suggest yourself a good summary, see Brother Video
The Sdimagecache class provides an instance of creating an empty cache and uses method Imageforkey: To find the current cache. UIImage *mycachedimage = [[Sdimagecache Sharedimagecache] imagefromkey:mycachekey]; Storing an image to the cache is a way to use Storeimage:forkey: By default, the image is stored in the memory cache and in the disk cache. If you only want to use StoreImage:forKey:toDisk in the memory cache: the third parameter of the method is replaced with a negative value.

8. Socket implementation process

Socket is the bottom of the network, Apple's original network processing, AFN, are based on the socket above to encapsulate

Nsstream is also a very important part of socket development.

9, local push and remote push.

Both local and remote push notifications can send messages to apps that are not running in the foreground, which can be either an impending event or a new server's data. Whether local or remote, they display the same effect on the program interface, which may appear as a warning message or a micro-chapter on the application icon.

The basic purpose of local and remote push notifications is for applications to be able to notify users of certain things and do not require the application to run in the foreground. The difference is that local notifications are called by the app, only from iOS on the current device, and remote notifications are sent to APNs by programs on the remote server. And then the APNS pushes the message to the program on the device.

10. Comparison

OC and C + + comparison:
Object_c is slightly slower than C + + because some of the language features of Object_c, such as reflection, affect the efficiency of execution.

The difference is mainly in the following aspects. Single inheritance: OBJECTIVE-C does not support multiple inheritance, (same as Java and Smalltalk), while the C + + language supports multiple inheritance.

Dynamic: Objective-c is dynamic training (Dynamicaly typed) so its class cubby C + + is easy to manipulate.

Objective-c can allow access to methods and classes based on string names at run time, and can also dynamically connect and add classes. C + + follows the Simula67 (an early OO language) school in object-oriented programming, while Objecive-c belongs to the Smalltalk school. In C + +, the static type of an object determines whether you can send a message to it, and for objecive-c, it is determined by the dynamic type.

The Simula 67 School is more secure because most errors can be detected at compile time. And the Smalltalk school is more flexible, such as some smalltalk seemingly unmistakable procedures to get SIMUALR 67 there will not be able to pass. In many ways, the difference between C + + and objective-c is more of a way of thinking than technology.

[PS: We implement multiple inheritance in C + + by protocol , an object that, once the protocol is adhered to, can implement a method of a protocol definition! ]

Compare Android to iOS:

    • Android using Java, easy to get started a lot, if there is a good Java lib, the development efficiency will be higher
    • iOS doesn't have a virtual machine, it's better performance, and of course the difference will be smaller as Google improves
    • iOS's development framework is basically common to Mac, the same knowledge can be developed for mobile phones, can also be developed for Mac applications, Android does not have such advantages
    • Android platform can do things far more than iOS, you can do phone management, address Book, SMS management, you can run the background service yourself. Replacing the components of the system is very easy
    • Android platform can also run other system runtime, such as Flash, with the NDK, you have to access a virtual machine yourself is also possible. Google doesn't care about you.
    • Anyone can use Android to make a separate system out of it, perhaps the meaning and prospect of doing so is problematic, but again, no one limits your

some workarounds for IOS arc vs MRC:

1. Using the MRC third-party library in the arc: in the compilation option, add the -fno-objc-arc tag for the MRC program, indicating that at compile time, the file uses MRC to compile

    (If you want to add an arc file to the MRC project, you can use the -fobjc-arc tag)

["Click on Project Name"--build phases--compile sources--"Double click File" configuration (Compiler Flags)--" add-fno-objc-arc"]

2. Compile the MRC third-party library directly into the static library for use

Note: You cannot add a dynamic library reference when compiling a static library

In the project, if you are using a static library that contains classifications, you need to add the-OBJC option to the other Link flag

3. Use Xcode's conversion tool--there is no success!!

---------

Featured Blogs

House of the broken ship: http://beyondvincent.com/archives/

IOS: 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.