Development

6 tips about adopting Swift in your company

We’ve been using the Swift language since the end of last year, when it reached version 1.0. Initially, we included Swift code in existing codebases but we have now moved to using almost exclusively Swift for new projects. The following tips are based on our experience in working with the language

1. Swift is still a fluctuating and changing language

Even though Swift has long reached version 1.0, it’s still a language that’s very much in development. This means that its syntax and structures can change with every new release, breaking existing codebases. Apple provides an automated conversion tool, but it seldom solves all your problems. The example below is from a medium-sized project written in Swift 1.2 and converted to Swift 2.0. Even after the automatic conversion, there are still 48 issues left.  Swift is a fluctuating language, so new versions can break existing code bases. 

2. Get your developers to follow news about the language’s development

Apple is usually good at discussing changes to the language before they’re actually implemented. Getting your developers to follow their official swift blog and look through the documentation of early beta releases. In this way, they’re more likely to be prepared to adapt your codebase when a new version is released by apple.

3. Use it for new projects

Swift 2 has recently been released together with iOS 9 and watch os 2. Many features that were missing have been added and the language feels a lot more polished. It definitely makes sense to start using it for new projects. There is now plenty of documentation and help available given that it’s been more than a year since the first stable (1.0) version became available. Using it for new projects will also avoid the need to work with legacy objective-c code. 

4. Avoid rewriting existing codebases

If you have a large, existing project you could start using Swift for new features first. The interface with Objective-C is good and well-established (as Apple uses it for their own frameworks), so try to avoid the temptation to rewrite large chunks of your battle-tested code. Over time more of your project will be in Swift as components that require changes are slowly improved and rewritten. Have a look at the concept of strangling vines if you have a large code base that will need be maintained for several years: 

5. Sell it to your clients / managers

In the long-run, Swift will replace Objective-C. There are now four platforms Mac, iOS, Apple Watch and the new Apple TV where Swift can be used. Given that the last two are very new, it makes sense to invest now in using swift there for new projects. Furthermore, Swift is a much safer language than Objective-C, which means less bugs and more time to concentrate on features.

6. Take advantage of the playground to prototype ideas

Swift has a powerful ‘playground’, a feature that allows developers to write code and see a preview of the results. This can be used to prototype all sorts of ideas including animations. By using this tool, you can discuss new ideas with your team, including designers, more effectively.

Join Devices in the Circle of Care

The Internet of things is a technology with a lot of potential in improving health and social care. We are currently working on a prototype that is funded by the Department of Health to allow different services and devices to connect with Jointly, an app that we developed with Carers UK that makes caring for someone a little easier, less stressful and a lot more organised.

The main use case is to connect use of drug dispensers with a circle of carers. We are creating an API that allows 3rd party services to create a circle of care, invite members and post messages back and forward from the device to Jointly. Technically we needed to do this while causing the least disruption possible in PivoTell’s product.

We opted to do it using the most ubiquitous Internet technology, namely, email. We setup a mailgun route to capture and process the emails and turned them into a nicely structured JSON format. Mailgun contacts parse.com where we have a cloud function to validate and authorise the request. From then onwards everything is handled as before, in iOS, android and web clients. We had to battle with some DNS settings and communication incompatibilities but as a prototype we are in good position to continue.