Appendix C. Cocoa Touch Static Libraries

WHAT'S IN THIS APPENDIX?

  • How to create a static library

  • Designing the static library to be an efficient component

  • How to include a static library in an Xcode application project

I am a big fan of reusability. I only like to write code once. Using Xcode, you can build a static library of useful routines so you don't have to write the same code repeatedly, or, worse yet, cut and paste the same code all over the place.

While it may seem harmless and easy to just cut and paste code wherever you need it, imagine you have several applications in the iTunes App Store already and you have just discovered a major bug in your code that causes the apps to crash. After spending hours tracking down the bug, you now have to fix it in all of the other applications — a tedious, time-consuming task.

Needless to say, this is not fun; and there is a solution, which is what this appendix is all about. In Chapter 10, "Data Storage," you worked through a contacts application using both property lists and Core Data. This appendix uses the property list application from Chapter 10, separating the data storage component and making it into a static library. That way, the contacts application focuses on user interaction, and the static library can be used for storing the contact information.

XCODE PROJECT TEMPLATE

Creating a static library is similar to creating an application; you merely choose a different template. The important thing to keep in mind about a static library ...

Get Professional iPhone® and iPad™ Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.