How to be a productivity ninja with the Swift coding language
When the iPhone appeared in 2007, the ensuing gold rush in app development included many apps that were almost 100 percent client-side. In other words, they had no (or almost no) capabilities that resided on servers, and the few that did often used third-party services.
I knew many nonprofessional developers who rushed into building apps, and I saw how they struggled with Objective-C, Apple’s pre-Swift coding language. There was little appetite for taking on additional programming languages and tools to build code that ran on a server. Developers were frequently limited by what they could do, which limited the apps. Many of you probably remember the wealth of flashlight apps.
This has changed over time, as users expected more capabilities from apps that required custom back-end services. For the professional developer world, this was not too challenging, but for nonprofessional developers, it posed a significant issue. Apple introduced Swift to make iOS developers more productive. Swift has evolved, and its productivity now has wider reach. For those looking to harness its capabilities, the following five benefits showcase what can be achieved:
1. Swift is in the cloud, on-premises and on the desktop
In 2015, Apple chose to open-source Swift, so IBM jumped in to create a server-side runtime environment called Kitura as part of its Swift@IBM program. Kitura is an HTTP server and web framework that is available for free and runs on IBM’s cloud, Bluemix. It’s also available to run on other public clouds, on-premises or even on a developer’s machine.
By running on the server, Swift enables iOS developers to leverage their existing skills to create back-end services. Typically, they will be creating APIs that will be called by their client applications running on iOS devices. This server code will have access to a host of additional services, including a wealth of these within Bluemix featuring IBM’s portfolio of cognitive (Watson), weather, data and other services. Developers can also connect to third-party services and back into on-premises systems.
Developers with Swift coding language skills are no longer limited to iOS devices but can now be more productive through building back-end services that result in more feature-rich apps.
2. Swift is on the server
There are many benefits to having Swift run on the server, beyond just reusing skills. Developers can port existing client code onto the server. For example, rather than having the client app communicate with multiple APIs, this work could be done on the server. Then, the client app has a single API to deal with. The following are some of the benefits of doing this:
- Reducing the amount of code and complexity within the app
- Optimizing the data traveling back and forth between the client and server, making the app more performant over lower-bandwidth or higher-latency networks, such as cell networks
- More updating can be done on the server, which is an easier and faster environment to deploy to than the app, where you have to go through Apple’s approval process every time
Server code can also be instrumented for capturing usage data that can then be mined for insights into app usage. This type of data is increasingly important, as creating the best user experience is becoming the competitive differentiator among mobile apps. Therefore, having fast and easy access to that data and the tools to analyze it is vital.
Developers are able to speed up development, be more responsive to change and have better-performing apps with better user experiences.
3. Swift provides a great developer experience
The Swift community has done more than just port the Swift language to the server. Where applicable, it has replicated as much of the iOS dev experience as possible. For example, there is support for familiar libraries such as Foundation and Grand Central Dispatch libraries. The idea is to make it as seamless as possible to move from client to server. This should reduce the time required to skill-up and allow developers to just get on with writing code.
Server code comes with its own requirements. For example, a client app will typically call APIs, whereas on the server, it is the API. Therefore, the Swift@IBM developers have made it easy to create code that responds to event calls. Again, this helps developers get their jobs done without a lot of new learning.
Perhaps the most powerful capability is the ability to debug Swift code running on the server from within the client development environment. This is provided through IBM’s Cloud Tools for Swift. XCode, Apple’s IDE for building iOS apps, can be used to write and debug code that runs in Kitura.
Developers can put a breakpoint into server code just as they would client code, and when the app runs and calls the server code, the breakpoint is triggered and the developers have access to all the insight needed to understand what is happening within their code (client and server) at runtime. This brings the type of developer productivity benefits to the iOS developer that we’ve seen when building for Android/Google Cloud Platform and Microsoft Windows/Azure.
To help developers onboard onto server-side, Swift@IBM has provided a number of resources, including the following:
- Sample patterns such as simple API, implementing SSL and connecting to an SQL database
- Example applications such as a to-do list app and a variant of Instagram
- A dedicated blog providing additional guidance and examples
- A public Slack channel where server-side Swift developers can discuss Swift development with the Swift@IBM engineers
4. Swift vs. other server-side options
For developers using alternate languages and frameworks on the server, there are some benefits of moving to Swift:
- The Swift community has made the language more performant than some other programming languages such as Ruby, so the app experience should be faster.
- Unlike some popular languages, Swift has better type safety, which should reduce the number of runtime errors. This makes developers more productive.
- The code is compiled, unlike many server-side scripting languages, which should improve the speed of execution and reduce errors. Devs spend less time fixing runtime errors.
For developers whose only development experience is with iOS and Swift, Kitura presents a great opportunity to enhance and create more feature-rich apps. They can do the following:
- Avoid the time required to learn new server-side skills or languages
- Take advantage of powerful server-side capabilities
- Speed up development times by moving code from the client to the server
This should solve a significant challenge facing nonprofessional developers.
For professional developers, there are benefits in potentially more performant server-side code as well as speeding up development through reducing the time spent fixing errors. However, the most compelling issue may not be having to wait for colleagues to build back-end services. For example, the skills to build back-end services may exist in an enterprise IT function, but there may be a delay before those resources can be deployed onto the project. Swift on the server allows the client app developers to build out the services they need without waiting.
In organizations with significant iOS resources and the need to move quickly, this benefit becomes more pertinent. It is unsurprising that Kitura has been popular within digital agencies. They would have the skills to build back-end services, but they need to deliver at higher velocities. Empowering app developers to create server-side code should speed up the whole build process.
5. Swift enables more productive developers and more performant apps
The result of this effort by IBM, as part of the Swift community, is to enable iOS developers to be more productive, in part by reusing skills. However, they can extend from the client to the server within the same familiar language and development paradigm, with support for needs that are specific to the server. This makes developers more productive in terms of being able to develop server-side code they would otherwise not be able to and to create that code faster.
For developers whose only skills are uniquely in the Swift coding language, this enables them use familiar dev tools to create far more feature-rich apps without learning entirely new skills. The results are faster development times and more performant apps. Server-side Swift and Kitura represent numerous productivity benefits for developers extending their client apps to the server.