GoldenJoe
GoldenJoe

Reputation: 8012

How should i handle a dependency in my static library?

I have written a static library which interfaces with a web service for internal use across multiple projects.

This library uses AFNetworking heavily, but so do the projects which will use the library. If I include AFNetworking in the library.

I get duplicate symbol errors, but if I remove AFNetworking from the library, it won't compile.

How should I address this dependency ?

Edit: My project is in a GIT repository. Whatever I do, other developers should be able to pull the project and have it compile successfully (unless I am wrong and I shouldn't be that way).

Upvotes: 0

Views: 70

Answers (3)

Brad Hughes
Brad Hughes

Reputation: 21

Use Cocoapods, you can add the dependency for AFNetworking and it will automatically add the library and everything will work like a charm. https://cocoapods.org/

Upvotes: 1

swapnilagarwal
swapnilagarwal

Reputation: 1174

The easiest solution is to rename AFNetworking Classes.

Go to each .m file of afnetwork, click on class name, then Edit->Refactor->Rename .There are around 10 files. It wouldn't take you long.

PS: A good practise is to prepend your library initials, for example if your library name is MyLibrary, you can rename AFNetworking classes like MyLibAFNetworking... MyLibAFHTTP....

Upvotes: 1

Kaushil Ruparelia
Kaushil Ruparelia

Reputation: 1178

Copy the files of AFNetworking project and add them to your project as files of your library. In other words,

  • Right click on any AFNetworking file in your project and do Show in Finder.
  • Select all the AFNetworking files.
  • Drag them to your Library project and then drop them.
  • When the pop up appears make sure Copy Items if needed is check marked.

Cheers!

Upvotes: 0

Related Questions