Creating Hello World App in Swift Using Xcode 6

The Hello World tutorial was the first programming article written for our iOS programming course. As Apple released Xcode 6, the tutorial is no longer up-to-date. We received quite a lot of emails about the tutorial update. So here you are. Instead rewriting the same tutorial in Objective-C, we’ll show you how to create the Hello World app in Swift. What’s more, we create a screencast for you.

If this is the first time you come across the tutorial, you may wonder why we teach you building a Hello World app. This programming tutorial is written for absolute beginners. We want to encourage you to learn programming. So the first app should be very simple. Despite its simplicity, the “Hello World” app serves a few purposes:

  • It gives you an overview about the syntax and structure of Swift, the new programming language of iOS.
  • It also gives you a basic introduction to the Xcode 6 environment. You’ll learn how to create a Xcode project and lay out your user interface using Storyboard. Even if you’ve used Xcode 5 before, you’ll learn what’s new in the latest version of Xcode.
  • You’ll learn how to compile a program, build the app and test it using the Simulator.
  • Lastly, it makes you think programming is not difficult. I don’t want to scare you away from learning programming. It’ll be fun.

You’ll need to use Xcode 6 (or up) to work on the Hello World project. If you haven’t upgraded to Xcode 6, just download it via this direct iTunes link.

Okay, let’s get started.
[Read more…]

How to Beta Test Your App Using TestFlight

Suppose you built an app and completed the testing of your app on a real device. So what’s next? Submit your app directly to App Store and make it available for download? Yes, you can if your app is a simple one. However, if you’re developing a high quality app, don’t rush to get your app out. I suggest you beta test the app before the actual release.

A beta test is a step in the cycle of a software product release. I know you’ve tested your app using the built-in simulator and on your own device. Interestingly, you may not be able to uncover some of the bugs, even though you’re the app creator. By going through beta test, you would be amazed at the number of flaws discovered at this stage. Beta testing is generally opened to a select number of users. They may be your potential app users, your blog followers, your colleagues, friends or even family members. The whole point of beta testing is to let a small group of real people get their hands on your app, test it and provide feedback. You want your beta tester to discover as many bugs as possible in this stage so that you can fix them before rolling out your app to the public.

You may be wondering how can you conduct a beta test for your app, how beta testers run your app before it’s available on App Store and how testers report bugs?

testflight-featured

In iOS 8, Apple released a new tool called TestFlight to streamline the beta testing. You may have heard of TestFlight before. It has been around for several years as an independent mobile platform for mobile app testing. In February 2014, Apple acquired TestFlight’s parent company, Burstly. With the official release of Xcode 6 and iOS 8, TestFlight is now integrated into iTunes Connect that allows you to invite beta testers using just their email addresses.

TestFlight allows you to arrange testing with external testers and internal users. Conceptually, both can be your testers at the beta testing stage. However, TestFlight refers internal users as members of your development team who have been assigned the Technical or Admin role in iTunes Connect. You’re allowed to invite up to 25 internal users to test your app. An external tester, on the other hand, is considered as an user outside your team and company. You can invite up to 1,000 users to beta test your app. There is a catch, though. Your app must be approved by Apple before you can invite your external testers for testing. This restriction doesn’t apply to internal users. Your internal users can begin beta testing once you upload your app to iTunes Connect.

In this tutorial, I will walk you through the beta test process using TestFlight. At the time of this writing, you can only arrange beta test for internal users only. So we will focus on beta testing with internal users. In general, you need to go through the below tasks to distribute an app for beta testing:

  • Create an app record on iTunes Connect.
  • Update the build string.
  • Archive and upload your app.
  • Manage beta testing in iTunes Connect.

Let’s get started.
[Read more…]

Announcing Our New Book: Beginning iOS 8 Programming with Swift

I’m thrilled to share this great news with you. Our second AppCoda book – Beginning iOS 8 Programming with Swift is now live and ready for purchases!

During the WWDC 2014, Apple surprised every iOS developer by launching a new programming language called Swift. I didn’t expect a new programming language to come out this year. I was expecting to see new APIs for iOS 8 along with a newer version of Xcode. This really surprised me and my friends too. I remember what one of my friends said to me. He told me, “You will have to rewrite your whole book again!”

Seriously. That’s a lot of work. So here comes the new book.

The first AppCoda book was basically an assortment of tutorials, which were published in this blog. It covered everything from the fundamental of Objective-C programming to more advance ones, where each programming technique was accompanied by a fully working app. I am really grateful that the practical approach has gained very positive feedback.

Beginning iOS 8 Programming with Swift

[Read more…]

Understanding Self Sizing Cells and Dynamic Type in iOS 8

In iOS 8, Apple introduces a new feature for UITableView known as Self Sizing Cells. To me, this is seriously one of the most exciting features for the new SDK. Prior to iOS 8, if you want to display dynamic content in table view with variable height, you would need to calculate the row height manually. Now with iOS 8, Self Sizing Cell provides a solution for displaying dynamic content. In brief, here are what you need to do when using self sizing cells:

  • Define auto layout constraints for your prototype cell
  • Specify the estimatedRowHeight of your table view
  • Set the rowHeight of your table view to UITableViewAutomaticDimension

If we express the last two points in code, it looks like this:

1
2
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension

With just two lines of code, you instruct the table view to calculate the cell’s size matching its content and render it dynamically. This self sizing cell feature should save you tons of code and time. You’re gonna love it.

self-sizing-cell-featured
[Read more…]

Introduction to UIAlertController, Swift Closures and Enumeration

Among all the changes in iOS 8 SDK, the changes of two commonly-used APIs in UIKit framework are less known. Both UIActionSheet and UIAlertView classes are now replaced by the UIAlertController class.

In iOS 8, whenever you want to display an alert message in your app, you should use UIAlertController instead the two deprecated classes. The action sheet and alert view become the style of the UIAlertController. You choose one of the styles when creating an alert controller. The way to handle button action is redesigned. You no longer use delegate (e.g. UIAlertViewDelegate) to handle user response. When using UIAlertController, you associate actions with the controller and that the action is expressed as a block in Objective-C or closures in Swift.

In this tutorial, I’ll give you an introduction to the UIAlertController and cover how to use the class to present an alert message, as well as, an action sheet. On top of that, I’ll take this opportunity to cover the basics of closures and enumeration in Swift.

UIAlertController Introduction

Okay, let’s get started.
[Read more…]

iOS Programming 101: Implementing Pull-to-Refresh and Handling Empty Table

In this iOS Programming 101 post, I would like to answer two common questions raised by our readers.

  1. I follow your table view tutorial to create my first app. The tutorial is great. It shows us how to display data in the table view. But what if the table is empty? When there is no data, the app should display a friendly message instead of just display empty rows. How can I do that?
  2. I like the pull-to-refresh gesture. It’s a great way for content update. How can I implement such feature in my table-based app?

    Let us first take a look at the first question and see how to display a text message when the table is empty. The UITableView class includes the backgroundView property, which is the background view of the table view. This property is set to nil by default. To display a message or an image when the table is empty, usually we configure this property and set it to our own view.

    uirefreshcontrol 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…]

First Time App Developer Success Stories Part 3: Am I Too Late to Learn iOS Programming

Am I too late to start learning iOS programming? Simply do a search on Google or Quora. You’ll see lots of discussions around the web. The mobile market has created tons of opportunities and possibilities. It’s amazing you can turn an idea into app that millions of people use. I’ve met a lot of people who love to create apps but think coding is difficult and it’s too late for them to learn to code.

It’s never to late. It’s the lack of determination and drive that keep you from learning programming. Some time ago, we shared the first and second parts of app developer stories. In part 3 of the series, we featured even more app developers to share their success stories. The ages of these first-time app developers range from 15 to 68 years old. Yes, you read it right. Robert Chalmers, one of the featured developers, is 68 years old! Though Robert got years of experience, it’s amazing he still keeps learning new programming language. I couldn’t imagine if I would still learn programming at that age. Rémy Spehler, who is a doctor by profession, started from zero programming experience to published his first app at the age of 58. The design of their apps is elementary and may not catch your attention. But they set a great example showing that everyone can learn iOS programming and build apps regardless of age.

first-time-app-showcase-3

I haven’t highlighted all the developers here but all of the stories are truly inspiring. Read on and check out their success stories.

[Read more…]

iOS Programming 101: How To Create Swipeable Table View Cell to Display More Options

When iOS 7 was first released, one of the many visual changes that particularly interested me was the swipe-to-delete gestures in the Mail app. By now you should be very familiar with the feature. After you swipe a table cell, you’ll see the Trash button, plus a new button named More. The More button will bring up an action sheet that shows a list of options such as Reply, Flag, etc.

I thought it’s a great feature to provide additional options for manipulating a table record. However, as you know, Apple didn’t make this feature available to developers in iOS 7. You can only create the swipe-to-delete option in table cell. The More feature is only limited to the stock Mail app. I have no idea why Apple keeps such great feature to its own app. Fortunately, some developers have created free solutions (such as UITableView-Swipe-for-Options, MCSwipeTableViewCell) and made them available freely.

In this tutorial, I’ll use SWTableViewCell and see how to implement swipe-to-show-options feature in your app. SWTableViewCell is pretty to easy to use. If you understand how to implement UITableView, you shouldn’t have any problem with SWTableViewCell. On top of that, it supports utility buttons on both swipe directions. You’ll understand what it means in a minute.

Swipeable UITableViewCell

Let’s get started and build our demo app.
[Read more…]