Documenting Your Objective-C and Swift Code in Xcode with HeaderDoc and Doxygen

During the development of an application there are various steps involved in the whole process. Some of them are the definition of its specifications, the creation of graphics, the implementation, and the testing phase following the implementation. Writing the code maybe consists of the most important part, as this brings the application to life, but further than that, equally important is the proper documentation of the code. No matter how well-written the code is, if there’s lack of a good documentation accompanying it, future troubles it’s possible to arise. Unfortunately, many developers overlook or ignore the importance of the code documentation, and that’s really bad, as good software is not just good code. It’s more than that.

When talking about documentation, apparently I don’t mean just to add a few lines of comments somewhere in the implementation files. It’s definitely more than that. But first, why is it such a big deal to document the code? Well, there are two cases: Whether you’re working on your own, or you are a part of a team. Let’s see in short each one.

xcode-macbook-featured

If you are the only developer of the under-development application, then it’s reasonable to believe that writing code documentation costs in time, so skipping doing that will bring you right into your target much sooner. Additionally, it’s easy to convince yourself that as you’re the sole developer there’s really no need to do that. But trust me, that’s the worst decision you might make during the app creation period. Suppose that you successfully implement the application, you sell it either on the app store or in a client of yours, and then you put it in the shelf. And after six months or so, you must create a new version of it by adding new features. When you open the project again and look to the existing code, a long before you write the first new line, you realize one killing truth: That you don’t remember almost anything! It’s hard to remember what you did, how you did it, and why! You must follow the one, painful way to wake that project up in your mind, which is no other than taking the project from the beginning and trying to “decode” your implementation line by line. Just a few comments here and there are not helpful, and eventually you end up making a super-effort for a long time until you understand everything. Many of you that you are now reading these lines may have come to that point, and I ensure you that there were times that I’ve been there too. This case is a real nightmare, and you often want to start building the project from scratch. And of course, the scenario described here would just be a… scenario, if we all invested a little time to write proper code documentation.

[Read more…]

Creating Simple Animations with Facebook’s Pop Framework

Editor’s note: When Facebook released its Paper app, it generated a lot of buzz in the app world. If you’ve used Paper before, the visual news feed reader, you should be amazed by its beautiful and fluid user interface. The design and attention to detail on the app is unmatched. The app refrains from using buttons and menus, but was built to be gesture-driven, to a degree that was uncommonly found in iOS apps at the time of its release. It went beyond Core Animation. The team has built its own animation engine to support all the smooth animations and coordinate animations with touch inputs. When I first tried out the app, I was wondering how some of the animations were implemented. Honestly I didn’t know how. A couple months later, the company open-sourced Pop, the animation engine behind its iOS Paper app. As a Facebook’s engineer described, Pop drives the scrolling, bouncing, and unfolding effects that bring Paper to life. Thanks to Facebook team. With the Pop framework, this means you can create similar animations that were found on Paper in your own apps.

The Pop framework was first released in late April, 2014. So far we haven’t written any tutorials about the framework. Thanks to Hossam who is kind enough to share with us an introduction of POP and show us how to create a few simple animations.

Enter the Pop tutorial.

pop-animations

In this tutorial, we will talk about Facebook POP framework to make great and easy animations in your own iOS apps. Like any other tutorials on AppCoda, I will help you understand and master Pop by examples. We will create four simple animations together to explore the framework.

Pop is an extensible animation engine for both iOS and OS X. In addition to basic animations including Linear, Ease-In, Ease-Out, Ease-In-Ease-Out animations, it supports spring (at the time of its release, spring animation was not supported in iOS), decay and custom animations:

  • Spring – dynamic animation that creates a nice bouncing effect.
  • Decay – dynamic animation that brings a movement to a smooth halt.
  • Custom – because the engine is designed to be extensible, you can create your own custom animations.

[Read more…]

Using Gesture Recognizers to Handle Pinch, Rotate, Pan, Swipe and Tap Gestures

Hello readers! iOS 8 is at the gates, as only a few weeks remain until the official release of the updated version of the operating system, and along with it, the release of the Swift programming language. So, as you understand, we are preparing to enter into a new era of the iOS SDK, where new wonderful technologies waiting for us to explore them! However, here at Appcoda we decided to dedicate one more tutorial to the existing SDK, using the Objective-C language. My next tutorials will focus on new iOS 8 technologies, and we’ll use the Swift language. Regarding this one, there were many candidate topics to write for, but ultimately the chosen one is about the Gesture Recognizers. So, let’s see a few things about them.

A gesture recognizer is actually an object of the abstract class UIGestureRecognizer. Such an object is related to a view, and monitors for predefined gestures made on that view. Going one level deeper, I would say that gestures are actually touches and movements of one or more fingers that happen on a specific area of the screen, where a view of interest exists there. In the early versions of iOS SDK, gestures recognizers were not provided to developers, so implementing such ways of interaction required a lot of manual work. Thankfully, Apple wrapped up all that manual work and gave it to developers as a single tool, and that way working with gestures became a really easy part of the iOS programming.

gestures-featured

[Read more…]

A Beginner’s Guide to Optionals in Swift

Swift was announced three weeks ago. Since then, I have been reading the Swift’s official guide and playing around with it in Xcode 6 beta. I started to love the simplicity and syntax of Swift. Along with my team, I am still studying the new language and see how it compares with Objective-C, a 30-year-old programming language. At the same time, we’re working really hard to see how we can teach beginner and help the community to pick up Swift effortlessly.

Two weeks ago, we covered the basics of Swift. In coming weeks, we’ll write a series of tutorials to cover a number of new features in Swift. This week, let’s first take a look at optionals.

swift-optionals-featured

[Read more…]

Getting Started with Swift: A Brief Intro to the New Programming Language

Along with the announcement of iOS 8 and Yosemite, Apple surprised all developers in the WWDC by launching a new programming language called Swift. At AppCoda, we’re all excited about the release of Swift. We enjoy programming in Objective-C but the language has showed its age (which is now 30 years old) as compared to some modern programming languages like Ruby. Swift is advertised as a “fast, modern, safe, interactive” programming language. The language is easier to learn and comes with features to make programming more productive. It seems to me Swift is designed to lure web developers to build apps. The syntax of Swift would be more familiar to web developers. If you have some programming experience with Javascript (or other scripting languages), it would be easier for you to pick up Swift rather than Objective-C.

If you’ve watched the WWDC keynote, you should be amazed by an innovative feature called Playgrounds that allow you to experiment Swift and see the result in real-time. In other words, you no longer need to compile and run your app in the Simulator. As you type the code in Playgrounds, you’ll see the actual result immediately without the overheads of compilation.

swift-playground

At the time of this writing, Swift has only been announced for a week. Like many of you, I’m new to Swift. I have downloaded Apple’s free Swift book and played around with Swift a bit. Swift is a neat language and will definitely make developing iOS apps more attractive. In this post, I’ll share what I’ve learnt so far and the basics of Swift.
[Read more…]

iOS Programming 101: How To Create Circular Profile Picture and Rounded Corner Image

One of the changes in iOS 7 is that it favors the use of circular image over square image. You can find circular icons or images in stock apps such as Contacts and Phone. In this short post, we’ll explore the CALayer class and see how you can apply it to create circular image or image with rounded corner.

You may not heard of the CALayer class. But you should have used it in some ways if you’ve built an app. Every view in the UIKit (e.g. UIView, UIImageView) is backed by an instance of the CALayer class (i.e. layer object). The layer object is designed to manage the backing store for the view and handles view-related animations.
The layer object provides various attributes that can be set to control the visual content of the view such as:

  • Background color
  • Border and border width
  • Shadow color, width, etc
  • Opacity
  • Corner radius

The corner radius is the attribute that we’ll use to draw rounded corner and circular image.

Circular Image using calayer

As always, the best way to understand how CALayer works is to use it. We’ll create a simple profile view with a circular profile photo.

[Read more…]

Announcing Our First AppCoda Book – Learn iOS 7 Programming from Scratch

I got something big to share with you. Our very first AppCoda book – Learn iOS 7 Programming from Scratch is now live and ready for purchases!

If you’re a follower of our blog, you know we encourage the “Get Your Hands Dirty” way (or what-so-called “Learning by Doing” approach) to study programming. Learning a new programming language is quite similar to learning a foreign language. You can’t just read a book and teach yourself Spanish (or any other languages). You have to practice, practice and practice! That’s the same for studying a new programming language.

This 400-page book is written with that in mind and based on our popular programming course. The book starts with the basics and walk you through the process to create iOS apps using iOS 7 SDK and Xcode 5. After you learn how to build a simple iPhone app, you’ll learn how to master table view and build a simple recipe app. Each chapter you’ll learn something more advanced than the one before.

Learn iOS 7 Programming from Scratch

Programming should be fun to learn. I tend not to bore you with programming concepts. Instead, you’ll get lots of hands-on exercises and create loads of apps in this 30-chapter book. You’ll need to code, debug and build some real apps. There are a lot of works to do but it would be a fantastic experience and you’ll master the fundamentals of iOS 7 programming along the way.

[Read more…]

Introduction to Objective-C Blocks

In programming, what differentiates a good developer from a great developer is the way each one takes advantage of the programming tools he or she offered by the used language. Objective-C, the official language for developing applications for iPhone, iPad and Mac OS, is a multi-featured one, and as a relative to C, very powerful. New developers have a lot to explore when starting working with it, while advanced programmers have always something new to learn, as there are numerous supported programming aspects. One of them, is the capability to write code using Blocks.

Blocks do not consist of a new programming discovery in Objective-C. They exist in other programming languages too (such as Javascript) with other names, such as Closures. In iOS, they first-appeared in version 4.0, and since then they’ve known great acceptance and usage. In subsequent iOS versions, Apple re-wrote or updated many framework methods so they adopt blocks, and it seems that blocks are going to be partly the future of the way code is written. But what are they all about really?

Well, a block is a self-contained, autonomous code fragment, existing always into the scope of another programming structure, as for example the body of a method. The code on the block can “interact” with the world out of it, but what takes place in the block is not visible to the scope out of it. Also, blocks can modify the values of variables being out of its body using a special way (we’ll see more later). Blocks have two great features:

  1. They can be executed in a later time, and not when the code of the scope they have been implemented is being executed.
  2. Their usage leads eventually to a much cleaner and tidier code writing, as they can be used instead of delegate methods, written just in one place and not spread to many files.
Introduction to Blocks

Focusing even more on the second feature, blocks offer a nice solution for creating callbacks instead of delegates, as they are declared and implemented directly to the point of the code where they are invoked. Using blocks, there is no need to adopt protocols, or implementing delegate methods that lead to much more code in a class. The best thing though, is that the callback procedure can directly access and use any variables existing locally in the scope where the block has been defined, so the need of passing data like we do in callback methods is eliminated. However, blocks cannot totally replace delegates as they cannot be used for every purpose. The best practice is to make combination of both, and that can be achieved both by following some simple rules and using the experience obtained in time.
[Read more…]

How To Import Contacts Using Address Book Framework

One of the most well-known and most used feature of iPhone devices to all users, developers or not, is the Address Book. For those who use a lot the device as a phone (rather than a mobile mini computer), all important and vital information they need exist in their contacts. Till today, many applications have been developed, and even more can be built that make use the device’s address book data.

Apple makes developers’ life easy, as it provides frameworks that allow to access the address book and deal with its records. Knowing how to work with address book and how to perform some basic tasks (at least), is a knowledge necessary to all developers, as either sooner or later they’ll come in need of integrating address book info into their applications.

Before we proceed to take a tour on the most important aspects of the address book framework through a demo application, it would be a nice idea to make an introductory discussion first that will make easier to everyone to comprehend what comes next in this tutorial. So, keep reading and surely you’ll find some pretty interesting stuff as food for thinking and study.

How To Add a Slide-out Sidebar Menu in Your Apps

Editor’s note: This post has been updated for Xcode 6 and iOS 8. The demo app now supports the latest version of SWRevealViewController.

How can I create a slide-out sidebar menu in my app? This is one of the most frequently asked questions we got from our readers. So this week we’ll show you how create a slide-out navigation menu similar to the one you find in the Facebook app.

For those who are unfamiliar with slide out navigation menu, 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.

Since Facebook app introduced this slide-out sidebar design, it quickly becomes a standard way to implement navigation menu. You can easily find this design pattern in most of the popular content-related apps such as Path, Mailbox, Gmail, etc.

Slideout Sidebar Menu in iOS

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.

With so many free pre-built solution on GitHub, we’re not going to build the slide-out navigation menu 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 and it’s available for free.

Read on and develop a demo app together.
[Read more…]