Best way to use static libraries for iPhone Projects

Source: Internet
Author: User

Address: http://www.iphone-geek.cn/%E7%BC%96%E7%A8%8B/iphone%E9%A1%B9%E7%9B% AE %E4%BD%BF%E7%94%A8%E9%9D%99%E6%80%81%E5%BA%93%E7%9A%84%E6%9C%80%E4%BD%B3%E6%96%B9%E6%B3%95

 

Because Apple prohibits external frameworks or dynamic link libraries from being used on the iPhone, you can only use the following methods to reuse code (third-party libraries or your own code:

  1. Add the Code directly to the project. This method is a bit stupid. For example, if a piece of your code is shared by five projects and you find a small bug, you need to change five places. Is it troublesome?
  2. Use a static library. This is a frequently used method. However, xcode does not provide a static library template for the iPhone. There are two solutions:

 

  • If your project mainly uses objective-C (C/C ++ can also be used, just make some simple modifications), you can use the ready-made xcode
    Template
    .
  • Use BSD static in static library under Mac OS X
    Create a static library. But to use it for iPhone projects, you still need to make some changes (you need to change the base SDK of the project to iPhone ).

 

 

But how can I link a static library to a project? If you are familiar with xcode, skip this section. Simple:

  1. The header file path of the static library is head search paths.
  2. Add the static library to the xcode project.
  3. Wp-image-504 "Title =" 4 "src =" http://www.iphone-geek.cn/wp-content/uploads/2009/12/4.jpg "alt =" 4 "width =" 383 "Height =" 354 ">

     

 

That's simple. But it's slow. Is everything okay? What if you want to modify your static library? You need to find your static library project from find and open it to modify it. Not like
Does Visual Studio include related projects in application projects? The answer is: yes, although there is still no visual
Studio workspace is easy to use. However, you can open the relevant static library directly from xcode. The method is to use xcode's cross-Project
Reference (cross-project reference ).

  1. Add the xcode project of the static library to the current project.
  2. Wp-image-505 "Title =" 5 "src =" http://www.iphone-geek.cn/wp-content/uploads/2009/12/5.jpg "alt =" 5 "width =" 298 "Height =" 383 ">

  3. Right-click the project under targets and add it to the association of the static library project.
  4. Wp-image-506 "Title =" 6 "src =" http://www.iphone-geek.cn/wp-content/uploads/2009/12/6.jpg "alt =" 6 "width =" 519 "Height =" 490 ">

  5. Under the project, expand the static library project and drag XXXX. A to link binary with libraries under targets.
  6. Wp-image-507 "Title =" 7 "src =" http://www.iphone-geek.cn/wp-content/uploads/2009/12/7.jpg "alt =" 7 "width =" 242 "Height =" 418 ">

 

In this way, you can double-click the static library project under the current project to open and modify the static library code.

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.