Ogre Codes

Follow @ogre_codes to get notified when new articles are posted to this site.

CocoaPods! Yay?

Jan 23, 2017 at 7:50 PM

After working for a few years on a project in Python with a fair number of outside libraries, I've grown to be very hesitant to include outside libraries unless the payoff is pretty substantial. Adding external dependencies adds a big cross section of code you don't fully understand and adds to the maintenance burden of your app. For our Django/ Python project this was particularly bad. Every time a new version of Django was released we have to ensure all the libraries we'd used supports the new version of Django then determine if we should wait for them to support the new version of Django. Is the developer of this external library reliable? How long does it take them to support a new Django release? We've twice been burned by libraries that got "left behind" and had to either re-implement a big feature or drop support for it. I've also seen many big security issues with Wordpress Plugins, and there have even been cases where secruity flaws were deliberately injected into libraries which worked their way into many applications. Another issue I've had to deal with is libraries that do upgrade on a timely basis, but which change APIs between versions so you have to re-implement a big section of your app in order to keep current.

While this tends to be a bigger problem with smaller open source libraries, large companies like Google and Facebook have abandoned large and seemingly healthy libraries behind.

While I'm not building on a framework like Django, Swift is a fast moving language with language features changing on a continual basis. If I add a library to my project, how long will it take them to adopt Swift 3.X or Swift 4.0? A few weeks? Six months? A year?

So my short checklist for whether I'll adopt a new library is as follows:

  • Does the library do something which I cannot do myself or which would take a large effort for me to implement?
  • Does the library have a track record of timely updates or is it mature enough to be stable without updates?
  • Is there a large enough community dependent upon the library where continued support is more or less guaranteed?

Even this checklist doesn't ensure you'll have a trouble-free experience with outside libraries. Facebook's Parse was dropped after years of development and while they've done a solid job of helping developers transition away from their platform, the burden is ultimately on the developers who built on top of that quasi-platform.

So part of my project requires uploading files via SFTP, seems like a fairly straight forward problem, but it turns out none of the base iOS libraries support SFTP, RSYNC, or any of the more common ways of moving files onto a UNIX server. So after digging through DuckDuckGo, then Google, StackOverflow, and a few other places, it seems the primary way of doing this is via libssh2, either using the library directly or via a wrapper like NMSSH. After looking over libssh2 for a bit, it seems like the support for iOS is fairly rough and making calls direct to a C API seems a bit intimidating for my first Swift app so I'm going with NMSSH which is an Objective-C library but one which has some decent Swift examples out there.

That decision made, I start looking at how to build it and decide I'll install it as a CocoaPod rather than by installing it direcctly at which point I run into one of the many frustrations of relying on external sources... just installing CocoaPods for the first time I ran into an installation error and a frustrating work-around. Hopefully the rest of this will go smoother, now I just need to learn how to integrate Objective-C into my app.

Update Success! With only a few small modifications I was able to get Swift calling NMSSH and authenticating against a server. I should be in business uploading stuff very soon.