K's iOS development and learning notes

Source: Internet
Author: User

This note is constantly updated. You are welcome to pay attention to and repost it and make progress together.

 

I. Object C and other basic concepts:

1) Use object-C # import instead # include

2) The default file Suffix of Object-C is. m, and the extension of Object C ++ is. Mm.

3) Class description and definition:

Declaration: @ Interface Class: parent {} @ end

Implementation: implementation starts with @ implementationclassname and ends with @ end

4) protocol Protocol: pure virtual class similar to Java interface or C ++

Declaration: @ protocol protocolname (methods you mustimplement) @ end

Call a protocol method: @ interface someclass <Protocol 1, Protocol 2>

Implementation: you do not need to list the methods in the header file. It can be implemented directly in the. M file.

5) Property: the compiler automatically obtains/sets the property.

Declaration: @ property (nonatomic, retain) uibutton * button;

Comprehensive: @ synthesize button;

6) object creation and release: all objects you create must be released. Otherwise, memory leakage may occur. By default, there is an Init () method. You can also implement the init method to initialize some variables.

Initialization:

-Simple Method: object * object = [[object alloc] init];

-Parameter method: object * object = [object alloc] initwithargument: argument];

Release: [object release];

7) Application delegate: An application delegate should be able to complete the following tasks:

1) at startup, you must be able to create an application window and display it to the user (applicationdidfinishlaunching ).

2) data must be initialized.

3) must be able to respond to the "Quit exit" Request (dealloc)

4) must be able to handle low memory warning (applicationdidreceivememorywarning)

Ii. iOS program performance and Response Speed Optimization suggestions

1) do not block the main thread
Put network requests and other tasks to the background thread for running.
2) use the memory effectively
3) Reduce the memory footprint of applications
-Eliminate Memory leakage: instruments can be used to track leakage in code.
-Make the resource file as small as possible
-Use core data or SQLite to handle big data

-Lazyloadng)

-Concatenate a program into the thumb format: the-mthumb switch can reduce the code size by up to 35%. However, for code modules with a large number of floating point operations, Please disable this option, because using thumb for such modules will lead to performance degradation.

4) Properly allocate memory

-Reduce the use of autorelease and use release more

-Set size limits for resources

-Avoid borderless problem sets
5) floating point calculation considerations
If the Code involves a large number of floating-point operations, do not use the-mthumb option to compile the code.
6) reduce power consumption

-Disable unused hardware functions, such as GPS and accelerator.
-Avoid polling because polling will prevent the CPU from entering sleep state. You can plan the work to be done through the nsunloop or nstimer class, instead of using round robin.

-Keep the idletimerdisabled attribute value of the shared uiapplication object as No. When the device is inactive for a period of time, the idle timer will close the screen of the device. If your application does not require the device screen to be turned on, turn it off. If you disable the screen to negatively impact your application experience, you need to modify the code to eliminate those effects, rather than shutting down the idle timer without having to worry about it.

-Merge tasks as much as possible to maximize idle time. Intermittent execution of some tasks at intervals consumes more energy than completing the same number of tasks at a time. Intermittent task execution prevents the system from shutting down hardware for a longer period of time.

-Avoid excessive disk access. For example, if you want to save the status information on a disk, save the status information only when the status information changes, or merge and save the status changes as much as possible, to avoid frequent disk write operations in a short time.

-Do not make the screen plotting speed faster than the actual requirement. From the perspective of power consumption, the overhead is very high. Instead of relying on hardware to suppress the frame rate of an application, you should draw frames based on the actual frame rate required by the program.

7) power-saving Optimization for online operations

Networking is the most power-consuming operation. The following principles should be followed to minimize network access:

-Connect to the external network only when necessary. Do not round-robin the server.

-When you need to connect to the network, transmit only the minimum data required to complete the work. Use a compact data format. do not include additional data that can be ignored.

-Send data packets in A group (inburst) as quickly as possible, instead of increasing the data transmission time. When the system detects that the device is not active, Wi-Fi and cellular wireless signals are disabled. Your application consumes more energy to transmit data over a long period of time than to transmit the same amount of data over a short period of time.

-Try to connect to the network through Wi-Fi wireless signals. Wi-Fi consumes less power than baseband Wireless, which is recommended.

-If you use the corelocation framework to collect location data, disable location update as quickly as possible, and set the location filter and accuracy level to an appropriate value. Core location uses the available GPS, cellular, and Wi-Fi networks to determine users' locations. Although the core location has tried to minimize the use of wireless signals, setting appropriate precision and filter values can completely disable the hardware when the core location does not require location services.

8) code optimization
The optimization tools provided by the simulator can be used to eliminate memory leaks and eliminate computing Hotspots caused by inefficient algorithms or known bottlenecks. But using instruments on a real machine for optimization is the only way to completely optimize the program before it is released.

Iii. Experience Summary

1) In objective-C ++, you can call methods using C ++ code or from objective-C. In both languages, objects are pointers and can be used anywhere. For example, the C ++ class can use the objective-C object pointer as a data member, and the objective-C class can also have the C ++ object pointer as an instance variable.

Note: xcode requires the source file ". MM" as the extension to start the objective-C ++ extension of the compiler.

OC ++ does not provide C ++ or C ++ functions for OC classes. Cannot inherit from each other

Summary:

The. M file can be mixed with C and objective-C code.

The. MM file can be mixed with C ++ objective-C code.

. C and. cpp cannot be mixed with objective-C code.

2) Compile and use static libraries

-Create a project named cocoa touch static library

-Call libstatic.:

Search paths> header search path> ../libstatic /**

Link binary with Library added to libstatic. A: Build phases

-Note whether the target of the Lib project is iosdevice or emulator. The former is arm7. the latter is i386 and cannot be mixed. However, you can use lipo to Package A. A file.

To be continued ~~~

 

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.