25 Tips and tricks for enhancing the performance of iOS Apps (intermediate) (3)

Source: Internet
Author: User
Tags sqlite database

25 Tips and tricks for enhancing the performance of iOS Apps (intermediate) (3) 2013-04-16 14:42 broken ship House beyondvincentfont Size:T | T

This article collects 25 tips and tricks for improving program performance into 3 different levels: Beginner, intermediate, and advanced. You can also click to view the introductory article.

AD: Network + Offline Salon | Mobile app Mode innovation: give you a reason to do the app >>

18) Reduce the impact of web and content

UIWebView is very useful. It makes it easy to display Web content and even to build content that uikit space is difficult to display.

However, you can be able to already notice that the program used by the UIWebView to build a safari program without Apple is fast. This is because JIT compilation restricts the use of the WebKit nitro engine.

So in order to get more performance, you need to adjust the size of the HTML. The first is to get rid of JavaScript as much as possible and avoid using large mines, such as jquery. Sometimes it's faster to use the original JavaScript than the other frames.

Also, try to load JavaScript files asynchronously-especially when the page behavior is not directly affected, such as parsing the script.

Finally-make the images you use the same size as you actually need. As mentioned earlier, use the sprite sheets as much as possible to save memory and improve speed.

For more information, take a look at: WWDC session #601 – Optimize UIWebView and Web content in your website in iOS.

19) Set the shadow path

If you need to add a shadow to the view live layer, how do you handle it? Most developers first add the Quartzcore framework to the project, and then add the following code:

    1. #import < Quartzcore/quartzcore.h>
    2. Somewhere later ...
    3. UIView *view = [[UIView alloc] init];
    4. Setup the Shadow ...
    5. View.layer.shadowOffset = Cgsizemake ( -1.0f, 1.0f);
    6. View.layer.shadowRadius = 5.0f;
    7. view.layer.shadowOpacity = 0.6;

One problem with this approach is that Core animation must make a off-screen (offscreen) to determine the shape of the view before rendering the shadow effect, and this off-screen operation is very resource-intensive. The following method makes it easier to render the system shaded: Set the shadow Path!

    1. View.layer.shadowPath = [[Uibezierpath bezierPathWithRect:view.bounds] cgpath];

By setting the shadow path, iOS doesn't always have to calculate how the shadow is drawn. Just use your pre-calculated path. The downside is that, depending on the view format, it may be difficult for you to figure out the path. Another problem is that when the view frame changes, the shadow path must be updated every time.

If you want to learn more about this, see Mark Pospesel's article: Shadowpath.
20) Optimize TableView

Table views require a fast scrolling-if not, the user will feel a pause. To make Table view smooth scrolling, make sure that you follow the following recommendations:

1. Set the correct reuseidentifer to reuse the cell.
2. Try to set the view to opaque, including the cell itself.
3. Avoid gradients, image scaling, and off-screen drawing.
4. If the row height is not the same, then cache it.
5. If the cell displays content to this network, make sure that the content is obtained asynchronously.
6. Use Shadowpath to set the shadow.
7. Reduce the number of subview.
8. Try to do fewer operations in Cellforrowatindexpath:. If you need to do some processing, then it is best to do it once and then cache the results.
9. Use the appropriate data structure to save the required information. Different structures lead to different operating costs.
10. Use RowHeight, Sectionfooterheight, and sectionheaderheight to set a constant height, rather than getting it from the delegate.
21) Choose the right data storage method


Choose the right data storage method
When you need to store and read large amounts of data, how do you choose how to store it? The following options are available:

1. Using Nsuserdefaults for storage
2. Save files in Xml,json or plist format
3. Archiving with nscoding
4. Store to a local database, such as SQLite.
5. Use Core Data.
What's wrong with using nsuserdefaults? Although Nsuserdefaults is good and easy, it is only for storing small amounts of data (such as your level, or the sound is on or off). If you are storing large amounts of data, it is best to choose another storage method.

Storing large amounts of data as structured files can also pose problems. In general, it is very resource-intensive to load all of the content into memory before parsing the structure data. Although you can use Sax to work with XML files, this is a bit complicated. In addition, all objects that are loaded into memory are not necessarily all needed.

So what about using nscoding to save a lot of data? Because it is also read and write to the file, there is still a problem with that.

To save large amounts of data, it is best to use SQLite or core data. With SQLite or core data, you can make specific queries--just get and load the data objects you need--to avoid unreasonable searches of your data. In terms of performance, SQLite and core data do not have much difference.

The biggest difference between SQLite and core data is actually usage. Core data represents an object model, and SQLite is just a DBMS. In general, Apple recommends using core data, but you can use a low-level sqlite if you have a specific reason not to use core data.

In the program, if you choose to use SQLite, here is a handy library Fmdb: You can use the library to manipulate the SQLite database without deep use of the SQLite C API.

25 Tips and tricks for enhancing the performance of iOS Apps (intermediate) (3)

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.