A Swift Tutorial for Google Maps SDK

Working with maps in iOS consists of an entire programming chapter, as there are tons of things that a developer can do with them. From just presenting a location on a map to drawing a journey’s route with intermediate positions, or even exploiting a map’s possibilities in a completely different way, dealing with all these undoubtably is a great experience that leads to amazing results.

Up to iOS 5.1 (including that version as well), iOS was using the Google Mobile Maps service to provide access to maps and all the related services. Since then however, things changed and Apple introduced the Map Kit, a brand new framework completely built in-house, which is used until today. By the time Apple stopped using Google’s map services, Google decided to create its own Maps SDK for all platforms, including iOS, and that way to compete the Map kit or any other map SDKs that other platforms use. Right now, Google consist of a strong player in this field, as many developers use that SDK. So writing for the Google Maps SDK for iOS is something that definitely worths to be done.

Google Maps API for iOS

At the writing time of this tutorial, the Google Maps SDK for iOS is in the 1.9.2 version. It contains many features, the most of what’s included in the web version of maps, but on the other hand there are missing features as well that are unable to work on a mobile platform. The remarkable point is that in this version, the SDK is quite large in size (MB), and surely that’s something you have to consider if you want to copy the framework’s source files in your project. However, the features it offers are pretty interesting and important so to be rejected without second thought.

[Read more…]

Building a Simple Share Extension in iOS 8 App

Share extensions, introduced in iOS 8, give users an easy and convenient way to share content with other entities, such as social sharing websites or upload services. Previously, sharing content usually entailed switching from one app to another, for example, while surfing in Safari, if you wanted to share a URL, you would copy it, switch to the app you wanted to save or share it in, perform the action and then resume surfing in Safari. With share extensions, users will now be able to share content to your service direct from within the app they are using, be it Safari, Photos or other apps. This isn’t limited to system applications. Any custom application that presents an instance of the UIActivityViewController class will be able to see your sharing extension if you built your extension so that it can handle the file type provided by that application.

We are going to build a Share extension that shares photos to a social networking site. To make things simple we’ll use Imgur for this as it allows users to upload images anonymously (without the images being linked to an account).

Share Extension

Just like any other extension, a share extension cannot be a stand alone app; it must come bundled with a container app. I’ve created a starter project that will be our container app. Download it to follow along.

[Read more…]

Creating Your Own Custom Controls Using IBDesignable in Xcode 6

Have you tried to create a custom control in older versions of Xcode? It’s not that easy. What makes it so hard is that you couldn’t see your design in the Interface Builder. Every time you want to review the design changes, you can only test the control in the simulator. That’s troublesome. You would probably need to spend hours and hours on designing a single component.

With the release of Xcode 6, Apple introduced a new feature known as IBDesignable and IBInspectable for developers to build custom controls and allowed us to live preview the design right in the Interface Builder. Quite obviously, this is a huge productivity benefit.

In this tutorial, I will give you an introduction to IBDesignable and IBInspectable, and show you guys how to take advantage of the new feature. There is no better way to elaborate a feature than creating a demo. So we will build a custom interface called “Rainbow” together.

Rainbow

[Read more…]

Introduction to Custom View Controller Transitions and Animations

Looking at the built in apps from Apple on your iOS device, you will notice the various animated transitions as you move from one view to another for example the way view controllers are presented in master-detail views with a swipe that slides the detail view controller over the master view controller as seen in the Messages app or Settings app and the various transitions that represent a segue to another view controller.

iOS 7 introduced custom view controller transitions which make it possible for developers to create their own animated transitions from one view controller to the next in their apps. In this tutorial, we’ll take a look at how to do this. We’ll also look at how to create gesture driven transitions called interactive transitions. To follow along, download the starter project which we’ll be using throughout the tutorial.

custom-view-transition

[Read more…]

Developing iBeacons Apps with Swift

Since the introduction of iBeacons with iOS 7 by Apple, a lot of things have been said and written about. iBeacon technology consist of a revolutionary way to keep track of the position of a device indoors and use location services, similarly to the GPS outdoors, and it’s based on the signal transmitted through Bluetooth (Bluetooth Low Energy specifically, or BLE) by beacon devices. iOS devices can do that also, as long as they run a proper application.

However, the most important thing is that iOS SDK allows to develop applications capable of monitoring for iBeacons, and then perform various actions, depending always on specific requirements. The use of iBeacons can be applied in a wide range of cases, especially for marketing purposes. For example, using iBeacons in retail stores targeted advertisements can be displayed on the customers’ devices once the device enters a beacon’s region, or keep track of the traffic in such stores. Actually, the example that I just described is already being used, and it can be evolved even further.

ibeacons-featured-photo

From the developer’s point of view, an iBeacon area can be monitored and handled almost like a location, therefore the meaning of regions exist in this case too. The only difference is that such a region is actually called beacon region. If you’ve ever worked in the past with location services, then you already know that the Core Location framework provides API to work with regions. With this, an app can be aware of whether and when a device enters or leaves a beacon region, how to identify and manage any found beacons and a lot more. Additionally, it’s possible for an app to track changes in the bluetooth state, so it can automatically stop monitoring for beacons and save resources when the bluetooth for some reason doesn’t operate.

[Read more…]

Building Action Extensions in iOS 8

Action extensions allow users to transform content originating in a host app without leaving the app. You can, for example edit images, change the text format, change the text itself, e.t.c. At WWDC 2014, Apple showed us a demo of an Action extension that translated the text of a web page to another language without leaving Safari.

Unlike the other extensions whose usage and purpose is clear, Action extensions do not have this clear-cut usage policy. For example, you can create an Action extension that shares content to social networks or one that can perform photo edits. In the Extensibility Programming Guide, Apple caution on picking the wrong extension point. In the case of Action extension, you should make sure that it’s appropriate for what you are trying to achieve and that another extension point won’t be more suitable for your purposes. In the previous given example, it would probably be more appropriate to use the share extension and the photo editing extension respectively instead of Action extensions.

ios8-action-extensions-featured

Action extensions are made available to users only when the extension specifies that it can work with the type of content the user is currently using. For example, if the extension specifies that it only works with text, it isn’t made available when the user is viewing images.

When you create a new Action extension, Xcode creates a template which when used without changing its configurations, will appear in every single action sheet by default. It won’t perform any checking of the content types to determine whether or not it’s appropriate for the host app. If you attempt to submit it like this to the App Store review, it will be rejected – you need to specify under what circumstances your extension should appear.

You can create two types of Action extensions – one with a user interface and one without. If you chose the latter, it will be limited to Safari, but if you provide a user interface, then the extension can be made available to other apps given that the extension supports the type of content to be transformed. We’ll look at both types of Action extensions.
[Read more…]

Xcode 6 Tips: Vector Images, Code Snippets and Many More

As a developer, no matter whether your are a professional one, or you are just doing programming for fun, it’s definite that you are going to spend endless hours in front of your monitor until your project is ready. Feeling comfortable with the programming tools you use is more than important, as they consist of your virtual workplace and everything defines the working conditions. And when I say “everything”, I mean it: From the applications that you’ll choose to use as tools, down to the last possible setting you may apply to any of them. Undoubtably, a friendly environment can boost up your performance; a less friendly, non-customizable programming tool can have the exact opposite effects, as your productivity can be dramatically reduced. For example, you may feel that you are fed up working with the same “ice-looking” tool without being able to modify its display settings, or you feel eye strain because characters are too small, or because you have to use the mouse because setting your own key combinations isn’t possible.

xcode6

So, hoping that I’ve made my point clear, let me make things more specific. As an iOS (and probably a Mac) developer, it’s quite possible that you use Xcode as your primary IDE (Integrated Development Environment) for developing your projects. I’m saying that is possible, because there are alternate applications you could use instead of Xcode. However, as most of developers use it, I’m going to stick to it. Anyway, Xcode is a powerful IDE, with numerous options and possibilities, and in its sixth version (in the time of writing) has nothing to be jealous of other IDEs. Each new version of it brings new features, making programmers’ lives easier. However, we all have to admit that Xcode is not perfect; It still has flaws, some of them quite annoying. But yet, it’s a great tool, and thankfully, Apple makes remarkable efforts to eliminate all flaws and bugs with every new update. In short, despite any flaws, Xcode is a great tool to work with.

Xcode, as any other programming tool, comes with some predefined settings. Its initial state serves the majority of the developers even from the first use, once it has been installed. With no doubts, Xcode has a great number of features, and for new developers or first-timers might look chaotic. Well, it’s a fact that not all options are for everybody. For example, if you don’t use versioning control, you’ll probably never going to use the respective feature. Or, unless you develop a really large project, you’ll probably never going to use bots for testing. But, no matter what you’re going to use or not, you must face one thing: Xcode is not made of stone, and it can be customized in many ways, so you can feel as comfortable as possible when working with it, and at the same time being extra-productive.
[Read more…]

Creating a Sidebar Menu Using SWRevealViewController in Swift

As promised, here is the Swift version of the slide out sidebar menu tutorial. Again we will make use of an open source library called SWRevealViewController to build the sidebar menu. Though the library was written in Objective-C, you can easily integrate it into any Swift project. You will see how easy you can access and interact with Objective-C classes using Swift.

Okay, let’s get started.

In this tutorial, I will show you how create a slide-out navigation menu similar to the one you find in the Gmail app. If you’re unfamiliar with slide out navigation menu, take a look at the figure on the right. Ken Yarmost gave a good explanation and defined it as follows:

“Slide-out navigation consists of a panel that slides out from underneath the left or the right of the main content area, revealing a vertically independent scroll view that serves as the primary navigation for the application.”

Slideout sidebar menu demo in swift

From what I know, the slide-out sidebar menu was first introduced by Facebook. Since then it quickly becomes a standard way to implement navigation menu. Nowadays, you can easily find this design pattern in most of the popular content-related apps such as Inbox, Digg, LinkedIn, etc.
The slide-out design pattern lets you build a navigation menu in your apps but without wasting the screen real estate. Normally, the navigation menu is hidden behind the front view. The menu can then be triggered by tapping a list button in the navigation bar. Once the menu is expanded and becomes visible, users can close it by using the list button or simply swiping left on the content area.

You can build the sidebar menu from the ground up. But with so many free pre-built solutions on GitHub, we’re not going to build it from scratch. Instead, we’ll make use of a library called SWRevealViewController. Developed by John Lluch, this excellent library provides a quick and easy way to put up a slide-out navigation menu in your apps. Best of all, the library is available for free.
The library was written in Objective-C. But it is very straightforward to integrate it in your Swift project. You will learn how it can be done in a minute.

[Read more…]

Building a Text to Speech App Using AVSpeechSynthesizer

iOS is an operating system with many possibilities, allowing to create from really simple to super-advanced applications. There are times where applications have to be multi-featured, providing elegant solutions that exceed the limits of the common places, and lead to a superb user experience. Also, there are numerous technologies one could exploit, and in this tutorial we are going to focus on one of them, which is no other than the Text to Speech.

Text-to-speech (TTS) is not something new in iOS 8. Since iOS 7 dealing with TTS has been really easy, as the code required to make an app speak is straightforward and easy to be handled. To make things more precise, iOS 7 introduced a new class named AVSpeechSynthesizer, and as you understand from its prefix it’s part of the powerful AVFoundation framework. The AVSpeechSynthesizer class, along with some other classes, can produce speech based on a given text (or multiple pieces of text), and provides the possibility to configure various properties regarding it.

text-to-speech-app

The AVSpeechSynthesizer is the responsible class for carrying out the heavy work of converting text to speech. It’s capable of initiating, pausing, stopping and continuing a speech process. However, it doesn’t interact directly with the text. There’s an intermediate class that does that job, and is called AVSpeechUtterance. An object of this class represents a piece of text that should be spoken, and to put it really simply, an utterance is actually the text that’s about to be spoken, enriched with some properties regarding the final output. The most important of those properties that the AVSpeechUtterance class handles (besides the text) are the speech rate, pitch and volume. There are a few more, but we’ll see them in a while. Also, an utterance object defines the voice that will be used for speaking. A voice is an object of the AVSpeechSynthesisVoice class. It always matches to a specific language, and up to now Apple supports 37 different voices, meaning voices for 37 different locales (we’ll talk about that later).

Once an utterance object has been properly configured, it’s passed to a speech synthesizer object so the system starts producing the speech. To speak many pieces of text, meaning many utterances, doesn’t require any effort at all; all it takes is to set the utterances to the synthesizer in the order that should be spoken, and the synthesizer automatically queues them.

[Read more…]

Creating Simple View Animations in Swift

Following the release of iOS 7 (and iOS 8 as well), animation and motion effects became central to the design of apps from both Apple and 3rd party developers. iOS 7 introduced a flat, minimal design to apps which inevitably resulted in some apps having a similar UI. To distinguish their apps from other apps, developers employed such features as animations and motion effects to make their apps stand out.

Not only are animations used to set your app apart, they can improve the overall user experience of your application. For great examples of how animations are used to improve UX, you should look at how Apple uses animations in their apps. For example, in the Photos app, when you select a photo from a collection, the photo expands out from the selected one and on closing it, it shrinks back to the selected photo. This adds to the navigation of the app in that it lets you know exactly where you were, if browsing many pictures.

view-animations-featured

Facebook’s Paper also employs animations beautifully to add to the overall user experience of the app. You select an article to read by flipping it up. This action, the fact that the article expands out from its thumbnail version, suggests that in doing the opposite, i.e. flipping the article downwards, would shrink it back to its thumbnail. Here, animation is used to convey how the app works and even a first time user of the app would soon be able to make assumptions on its use and figure out its navigation without needing a tutorial.

Not only do animations add to the user experience of the app, but they could be what delights and impresses your users guaranteeing repeat usage instead of uninstalling the app for a better one from the App Store.
[Read more…]