Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create reusable code in iOS?

I've been working on a mobile app for a couple of months. Now I want to develop other apps but reusing the code I've written. I'd like to have reusable code (ViewControllers) in order to be used in many projects. In this way, if there is some bug in one of these, I'd fix the bug and then apply the changes to all the projects that use my library. In short words, I'd like to know what is the best way to develop my own library for iOS with XCode. I've been developed for Android but I'm new in iOS development.

  1. Is it possible to add my own library to CocoaPods?
  2. Do you suggest any other alternative?

Thank you very much

like image 655
Camilo Sacanamboy Avatar asked Apr 05 '15 22:04

Camilo Sacanamboy


2 Answers

Yes, you can create your private, internal, pods and make your applications depend on them. As an alternative you could use git submodules either.

But if you want you can even use both: having your private pods, which are also git submodules of your project, - they are usually called Development Pods - because you might want to fix a bug on your internal pod and push the fix immediately to the bleeding edge of your library as soon as you tested it on the application in which you spotted the bug in the first place.

A couple of interesting articles on this topic:

Working with internal pods

Development pods

On a totally side and obvious - I think - note, you can do this manually as pointed out by user1118321.

like image 93
HepaKKes Avatar answered Oct 01 '22 18:10

HepaKKes


You can create a static library or a framework (shared library). From the "File" menu choose "New Project" and then click on "Framework&Library" under "iOS". Then choose "Cocoa Touch Static Library" or "Cocoa Touch Framework".

like image 33
user1118321 Avatar answered Oct 01 '22 17:10

user1118321