Monday, 21 January 2013

[iOS] Create static library

As mentioned in my earlier blog, 2 of my apps needed a pin challenge view. In order to share the code, it was better to create it as a library.

I managed to find a good base code in "PinView" at guicocoa.

However, I needed to enhance it to include a custom button on lower left corner as well as make the "delete(x)" key same color as other keys. I'll leave those code details for another posting.

Step 1. Download pinview at git

Step 2.  Below is the directory structure of "PinView" sample app, where the PinView code will be under "pinview" directory. Make a backup of this directory and save it at another location.

Step 3. open the SampleApp project by clicking on the SampleApp.xcodeproj.

Step 4. In order to create a clean directory structure, we need to first delete the pinview directory. Ensure "Move to Trash" option is selected in the confirmation dialog.

Ensure the "Move to Trash" option is selected.

Step 5. Create a new "Cocoa Touch Static Library" target, by selecting "File > New > Target".

Step 6. I maintained the "pinview" name.

Steps 7. Xcode generated some code for us, which we don't need. So, delete them and choose the "Move to Trash" option.

Steps 8. Notice the pinview directory now only contains the pinview-Prefix.pch.

Step 9. Copy all the code you backed up in Step 2. and paste them into pinview directory.
 Next, in xcode, add all the files under pinview directory.

Step 10. Next, add the new library by selecting "SampleApp" under Targets, > Build Phase > Link Binary With Libraries > "+". Next, select the libpinview.a and click "Add".

Now, you are ready to run the SampleApp.

1 comment: