Transition to Server-Side Swift with BluePic
In order to demonstrate the possibilities a developer has using open source Swift, IBM built the open sourced demo application known as BluePic. This article will provide you with an overview of the technologies BluePic uses and how it leverages server-side Swift. BluePic is a photo sharing application for viewing, posting, and searching for images posted by others. This application takes advantage of Swift in a typical iOS client setting, but also on the server-side using the new Swift web framework and HTTP Server, Kitura.
Kitura was built and open sourced by IBM to provide a web framework and server for developers wanting to leverage Swift beyond the iOS client ecosystem. With Kitura being written in Swift, one developer can develop their Swift application on the front end and easily transition to developing on the back end, since Swift runs well on both.
A Reason to Change
For many iOS developers, the question of, why bother to create their own server, may come up. You have an iOS client, some APIs to connect to, and a database, so why create a custom server in Swift? A great answer would be control, because when there is no middle-tier, no server-side app with logic, the iOS developer knows very little about what happens when they make any network request. Having a server-side app using Kitura, allows for more customization and quicker troubleshooting since you aren’t waiting on a third-party to address issues that come up. Plus, in this case, you get all the benefits of having that middle-tier while still using Swift, making the decision less difficult for many iOS developers.
The Technology of BluePic
In addition to the server-side app, BluePic is made possible because of a handful of services hosted on IBM’s cloud offering, Bluemix. The architecture diagram above should provide some clarity as we walk through the different components of BluePic. Cloudant is used as the main data storage for recording user and image data, while Object Storage is used to store the image binaries that are loaded into the iOS application. Mobile Client Access (MCA) is used on both the front end and the back end for enforcing security. In the iOS app, MCA is used to authenticate users to post images and be able to view their profile with images they have posted. On the back end, MCA protects certain end points so an unauthorized user cannot get data from or post data to them. Similarly, IBM Push plays a part on both ends by registering an iOS app on the front end to receive push notifications, while, on the back end, it sends a request to the Apple Push Notification Service, when an image is done processing. This ultimately guarantees that a push notification is sent to the iOS client.
BluePic also makes use of the Insights for Weather and AlchemyAPI services on Bluemix. We leveraged Insights for Weather to get weather data like temperature and current weather situation (e.g. cloudy, sunny) for the particular location an image was being uploaded from. This info is displayed on an image detail page within the iOS app. AlchemyAPI is used to analyze every image that is uploaded in order perform object and scene recognition. For example, AlchemyAPI might classify an image of a beach as “beach”, “sea”, and “sand”. All these services play a crucial part in the complete experience of BluePic. We integrated both of these services into the OpenWhisk event-driven platform.
If you feel overwhelmed by everything going on in BluePic, then look no further than IBM Cloud Tools for Swift. Designed for Mac developers specifically, IBM has developed IBM Cloud Tools for Swift in order to ease the process of setting up and managing your server-side environment on Bluemix. It enables you to create and deploy your own instance of the Kitura-based server and provisions the necessary services for the BluePic app to run on Bluemix. There are a few optional, yet manual steps mentioned in the BluePic README, but the vast majority of work can be done through IBM Cloud Tools for Swift. While IBM Cloud Tools for Swift provides an extra layer of convenience, for all the non-Mac developers, you can still accomplish everything you need using Bluemix directly. The intent is that BluePic can demonstrate to developers the ease of using Swift on the front and back end, as well as the variety of integrations that can be used with a Swift-based server. Then, with the addition of IBM Cloud Tools for Swift, all that becomes much easier for the developer.
BluePic is just one example of what is possible with an iOS app running on a Swift Kitura-based server. BluePic is now open sourced so developers can see implementation details and have a reference to build their own Kitura-based server app. Here at IBM, we believe we are taking big steps in making Swift more valuable as a server-side language. One way we do that is by providing structure and examples for developers to follow. We see this through the Kitura web framework and through the availability of Bluemix services you can use in your application.
If you want to see a demo and learn more about BluePic, you can check out IBM’s talk at WWDC 2016, “Going Server-side with Swift Open Source”. For running your own instance of the BluePic iOS app and server, you can head to the BluePic README for documentation on how to get started.
via Swift@IBM http://ibm.co/2eqyWbZ
November 15, 2016 at 08:03AM