How to use open source iOS libraries without collisions?

I am writing an iOS library (SDK) and I need JSON decoding support. There are many options, but the problem is an upstream collision.

If I add, say, JSONKit to my library, and another third-party library does the same, then the upstream user who wants to use both my library and another library will encounter a conflict.

Then it would be impossible to add third-party libraries to the library due to the risk of collisions. How can I use iOS libraries as my dependencies without causing collisions for upstream developers?

+6
source share
3 answers

How can I use iOS libraries as my dependencies without causing collisions for upstream developers?

Just indicate that this third-party library is a dependency of your library, provides relevant links to the project and any necessary instructions, version information, etc.

If this package / distribution is not suitable for distribution (for example, they only have source files), then create a public project (fork) that includes the correct static library target.

+2
source

We have the same problem. Here are my thoughts on how to solve it (maybe we can find a reliable solution together). For version control we use Git:

  • One option is simply to prefix all classes in your library with your own identifier. In this case, even if the class is part of JSONKit, I would still prefix it with my own identifier ("JG") to get the class name "JGJSONKit.h". Thus, it is much less likely that a collision will occur.

    This method has a drawback that should be updated with a third-party repository (for example, JSONKit), however, it is more difficult to extract these changes in our library version of JSONKit.

    This may be acceptable, however, if this code is intended to be exported as a static library (since you will still maintain full control over the code, and you can manually make changes to third-party repositories and rename them accordingly if you so wish to do so in future updates to the static library).

  • Another option I reviewed is to use Git submodules. This solution seems to be better if your library is open source (or at least open source for developers who have access to it) that are not necessarily publicly available). In such cases, developers might simply not include any submodule that they have already used in their own project.

Ideas?

Edit:

Here is the solution we came up with:

1) We encapsulated our common code (which we wrote - not to a third party) in the project with the static purpose of the library and our shared resources (xibs and images) in the kit following this guide:

https://github.com/jverkoey/iOS-Framework

2) We created a Git repository that included the specified static library and package.

3) We forked all the necessary third-party libraries (so that we could make changes to them, if necessary), and also added the source repositories as another remote in each forked repo (so that the changes were made upstream, we could easily them pull into our own plug)

4) We have added the -objc flags for the "other linker" ( important ) so that all categories work correctly at runtime.

In general, the solution is ideal for us:

We avoid collisions by either hiding third-party libraries ( not including them in public headers, but private instead), or we warn that these libraries are used in the project for public headers and that developers should not add them again (instead they can use already included code, which is updated by the ease of including them through the specified Git submodule)

I hope this helps your efforts too!

+1
source

I looked at JSONKit and I see that this is not a static library, this is an src file to copy to your project.

All classes, etc. your project must have a prefix of your (cough) globally unique two-letter prefix, including classes that you copy and paste onto the Internet.

You would be better off if JSONKit was a library. Your library will depend on JSONKit, but not contain it, and everyone who created the application with your library would be sure that JSONKit is also included and linked with - without collisions (although the distribution of the library depends on another third-party library that does not belong you, in fact, are somewhat complicated).

If other people paste this JSONKit file into their libraries and then distribute them, you have only two options:

Change JSONKit.h and .m, the prefix of all the characters (should you do this using any code that you specify as the source) or choose something else (NSJSONSerialization?).

This does not mean that you cannot have dependencies of third-party libraries (or that it is dangerous), just copying the source file to your project does not coincide with adding a library dependency.

* arghh, ok 3 .. you can weakly bind all the characters from JSONKit and leave it to the library user to supply JSONKit.m, but then the problem is with other libraries.

TL; DR .. avoid JSONKit, it is not recommended to use "as is" in the library that you want to distribute.

0
source

Source: https://habr.com/ru/post/925685/


All Articles