The Tampa Bay tech scene, February 7 – 17, 2017

by Joey deVilla on February 6, 2017

Figures in map show incoming LinkedIn members per 10,000 LinkedIn users. For example, for every 10,000 LinkedIn members in the Tampa Bay area, 48.7 have moved in since December.
Click the map to see the source article.

According to LinkedIn’s February 2017 workforce report, the Tampa Bay area is one of the top 10 U.S. cities that recently gained the most workers. That’s one of the reasons why there’s a lot happening in the local tech scene, and here’s what’s happening over the next couple of weeks…

St. Pete .NET’s Using Docker for development and production (Tuesday, February 7)

Using Docker for development and production: “We are going to explore how we can leverage Docker for use while we develop our applications as well as once we are ready to deploy. We will discuss creating a container that will allow us to work on our .NET Core application in a way that incorporates live rebuilds, debugging, and continuous testing.”

Tampa Bay Android Developer Group’s monthly meetup (Tuesday, February 7)

 The Tampa Bay Android Developers Group holds its monthly “30-minute talks, roundtable and socializing” meetup at The Iron Yard on the first Tuesday of the month, which is this Tuesday.

MADTampa’s Windows Developer Day get-together (Wednesday, February 8)

 The Mobile App Development Tampa group — MADTampa for short — is hosting an event where you can watch Microsoft’s big Windows Developer Day livestream at the Tampa Microsoft office. Join the Fustino Brothers and watch the livestream to see:

  • What’s new with Windows developer tooling: UWP tooling, BASH, Developer mode, and more
  • Learn about the latest XAML advancements, and how UWP helps you build Windows apps that are more personal and productive
  • Hear the developer story behind the recent announcements of Cortana skills and the new Windows mixed reality headsets
  • We’ll also close out the event with a live Q&A panel, where anyone can ask their questions
  • RSVP for this event at EventBrite
  • 12:00 p.m. – 3:30 p.m. @ Microsoft Tampa (5426 Bay Center Dr. in Tampa, Suite 700)

Suncoast Developers Guild’s Open Code (Wednesday, February 8)

 Every Wednesday, the Suncoast Developers Guild holds an Open Code night in The Iron Yard. It’s a great opportunity to work on your projects and meet other local developers in a fantastic space (The Iron Yard is in a lovely old factory building).

Tampa Bay UX’s How to be a badass designer in 2017 (Thursday, February 9)

 The Tampa Bay UX Meetup this Thursday will feature Krissy Scoufis talking about how to be a badass designer in 2017. She’ll talk about hot UX topics including:

Tampa Bay Cocoaheads’ talk on making Swift and Objective-C work together and book giveaway (Thursday, February 9)

 Another Tampa Bay Meetup that covers iOS development — Chris Woodard’s Tampa Bay Cocoaheads — is holding its first meetup of the year on Thursday. The topic of the evening will be making Swift and Objective-C work together, based on his experiences migrating a large codebase.

This meetup will feature a giveaway: autographed copies of Swift Programming: The Big Nerd Ranch Guide and iOS Development: The Big Nerd Ranch Guide.

Demo Day at The Iron Yard (Friday, February 10)

 The Iron Yard is a coding school, and on Friday, its 6th cohort will present their capstone Ruby on Rails, JavaScript, and .NET projects. These projects are the culmination of their 12 weeks of intensive training. They’ll present them to an audience of local tech companies, engineers, and supporters of the tech community, after which they’ll be happy to personally demonstrate their projects to you. There’ll be drinks and appetizers, too!

Tampa Bay Startup Week 2017 (week of Monday, February 13 through Friday, February 17)

It’s that time of the year again: Tampa Bay Startup Week! It’s a week-long series of events for local entrepreneurs, techies, and interested parties to get together, learn, chat, conspire, and break bread and clink glasses. Visit their site and see (and sign up for) events that you might be interested in!

Ybor Tech’s February OpenHack (Tuesday, February 14)

 One of my favorite local events is Ybor Tech’s OpenHack, which is simply an excuse for local developers, techies, entrepreneurs, and other similar people to get together at New World Brewery in Ybor City to enjoy pizza, beer (or cider), and each other’s company.

{ 0 comments }

Click the screenshot to see the original page.

Kudos to the marketing people at BenQ, who are promoting their Zowie line of monitors not just as computer monitors, but as monitors for that most fakety-fake of categories, e-sports. Better still, they weren’t satisfied with just using e-sports as a respectable-sounding neologism of “not actually participating in a sport, but sitting on your ass for hours playing videogames”, but inventing two subcategories, “console e-sports” and “PC e-sports”.

Videogaming is fantastic fun and has many merits and requires skill, so there’s no need to gussy it up with a purposely misleading name like e-sports. Let it be what it is.

{ 2 comments }

Tampa iOS Meetup: The dreaded tip calculator, part 2

by Joey deVilla on February 6, 2017

Here’s the second in a series of articles based on the most recent Tampa iOS Meetup, where I walked the group through building a tip calculator. If you’re new to iOS development, you’ll may find this series a useful introduction.

(And if you’re in the Tampa Bay area, perhaps you’d like to join us at the next Tampa iOS Meetup, currently scheduled for Tuesday, February 28th.)

Other articles in this series:

The story so far: What we did in the previous article

In the previous article, we put together a simple application featuring one button and one label:

If you tap the button, the text of the label changes to Hi there!

Right now, the app doesn’t act anything like a tip calculator should, but over this series of article, we’ll turn it into one. Along that way, you’ll become familiar with a number of aspects of iOS programming, including Xcode, the Swift programming language, and a couple of iOS user interface objects.

This article will start from where the previous article left off. You can either follow its steps, or if you prefer, you can start with the completed projects from the previous article.

What we’ll do in this article

A tip calculator has to have some way for the user to enter a dollar amount so that a tip for that amount can be calculated. In this article, we’re going to add a text field to our app as the first step in converting our simple app into a tip calculator.

By the end of this article, our app will look like this:

The user will be able to type text into the text field, and when s/he taps the Tap me button, the label will display the text in the text field:

I’ll admit that it won’t calculate tips, but by providing a text field and being able to read its contents, we’ll be a step closer to having a functioning tip calculator.

Let’s add a text field to our app

A tip calculator has to have some way for the user to enter a dollar amount so that a tip for that amount can be calculated. We’ll use a text field as that way.

We want to put the text field near the top of the view, so we’ll need to:

  • Move both the button and label farther down on the view so that there’s enough space near the top to place a text field.

Like the button and the label, the text field is a user interface object that you can get from the Object Library, which is part of the Libraries section of the Xcode interface, and located near the lower right-hand corner. Look at the lower right-hand corner and make sure that the Object Library icon is highlighted…

…and then look for the Text Field object in that list. There are a lot of objects in the Object Library, so you can either scroll around for Text Field, or you can pare down what’s shown in the list by using the Filter box at the bottom:

Do the following:

  • Type text into the box.
  • The Objects Library will respond by displaying only those objects with text in their names. One of them is the Text Field, and that’s what we want to add to our app’s view.

  • Drag a Text Field from the Object Library and onto the view. Place it near the upper left-hand corner of the view. As you bring the button close to that corner, Xcode will cause a couple of guides to appear. Line the text field up with those guides.

  • We want to provide the user with enough room to enter a few words into our text field, so widen it so that it goes about two-thirds of the way across the view.

Connect the text field to the view controller

Now that we’ve added a text field to the view, we need to make a connection between it and the view controller. In the previous article, we said that there were two kinds of connections you could make:

  1. Outlet:
    • In the view controller, an outlet is a variable that contains a reference to a specific object (such as a label, button, or text field) in the view. It’s marked with the @IBOutlet keyword, which tells Xcode that it isn’t just a variable, but an outlet.
    • Allows the code in the view controller to “talk” to an object in the view.
    • By connecting an object in the view to the view controller with an outlet, the view controller can:
      • call that object’s methods,
      • set one of its properties (such as the text it displays, its color, and so on), and
      • get the value of any of its properties.
    • The bottom line: If you want to call the methods for an object in the view, or get or set its properties, use an outlet.
  2. Action:
    • In the view controller, an action is a method that gets called in response to a specific event occurring for an object in the view (such as when a button is tapped, or the text in a text field is changed). It’s marked with the @IBAction keyword, which tells Xcode that it isn’t just a method, but an action.
    • Allows an object in the view to “talk” to the code in the view controller.
    • By connecting an object in the view to the view controller with an action, the view controller can:
      • Respond to specific events that occur for the object.
    • The bottom line: If you want to respond to the events for an object in the view, use an action.

We want a connection that will allow us to get the contents of the text field. An outlet will allow us to do that.

Once again, we’d like to have both the view (which lives the in Main.storyboard file) and the underlying view controller code (which lives in the ViewController.swift file) visible at the same time. We’ll use the Assistant Editor, which allows us to view two files side by side.

The Assistant Editor button is located near the upper right-hand corner of the Xcode interface. Do this:

  • With the main storyboard visible in the editor area in the center of Xcode, click the Assistant Editor button. Xcode tries to be “smart” about which file you want to edit, and in this case, it should “assume” that you want to look at the app’s only view’s view controller code.

You should see something like the screenshot above. You may want to expand the Xcode window so that it takes up the entire screen.

Let’s connect the text field to the view controller:

  • Select the text field on the view in the main storyboard, then control-drag (that is, drag while holding down the control key on the keyboard, or if you have a mouse, right-drag) from the view to the ViewController.swift code.
  • Let go of the mouse in the empty spot between
    @IBOutlet weak var replyLabel: UILabel!
    and
    @IBAction func buttonPressed(_ sender: Any) {

A pop-up will appear:

Do the following with the pop-up:

  • Select Outlet from the Connection menu.
  • Give the outlet a name: enter initialAmountField into the Name field.
  • Click the Connect button.

The text field is now connected to the view controller.

Changing what the button does

At this point, the code in ViewController.swift should look similar to this:

We want to change the code so that when the user taps the Tap me button, the text of the label is set to whatever text is in the text field.

The buttonPressed method — which is also an action — is executed whenever the user taps on the button, so that’s where we’ll want to make the change. Change the contents of buttonPressed so that it contains just this line:

The code in ViewController.swift should now look like this:

Run the app. You should see this:

Now enter some text into the text field:

Now tap the Tap me button. You’ll know the app is working as expected when the contents of the label are the same as the contents of the text field:

Now that the app can accept user input and do something simple with it, we’re a step closer to having a working tip calculator. In the next installment, we’ll make our first actual tip calculation!

Download the project files

Although this is an extremely simple project, I’ve made its files available for download — click here to get them!

{ 0 comments }

Beginner-friendly git tutorials and guides

by Joey deVilla on February 3, 2017

At the most recent Tampa iOS Meetup, someone asked me where they could find some beginner-friendly tutorials and guides for people new to git and version control in general. I promised to post a list of them, and here they are:

{ 0 comments }

A lot of programming is JUST. LIKE. THIS.

by Joey deVilla on February 3, 2017

Found via imgur.

{ 0 comments }

Here’s the capsule review: iOS 10 Programming for Beginners, written by fellow Tampa developer Craig Clayton, is a great book. If you’re new to programming, it’s for you, because it doesn’t assume any prior programming experience. If you have programming experience but are new to iOS programming or the Swift programming language, you’ll also find it useful. Hey, I’ve been programming for years, I have an app in the App Store, and I run Tampa iOS Meetup, and I learned a couple of things from it!

Craig knows what he’s talking — and writing — about. He organized and ran the Suncoast iOS Meetup here in Tampa as well as intensive iOS coding academies, and he makes a living writing mobile apps. If you’re a Patriots fan with an iPhone, chances are you’ve used his app (pictured on the right).

iOS 10 Programming for Beginners starts with the basics — getting familiar with Xcode, the tool used for writing iOS apps — and then spends a couple of chapters getting you up to speed with Swift through the use of programming exercises in Xcode’s playgrounds.

Once the book has provided you with enough Swift knowledge to be dangerous, it spends a couple of chapters introducing iOS’ UI elements and basic application architecture. The final two-thirds of the book is devoted to building a single application: Let’s Eat, a restaurant review app that becomes more sophisticated and gains more features with each chapter. Each chapter begins with an explanation of the topics that will be covered, and features both clear explanations of those topics, along with step-by-step instructions for turning those topics into working code. Craig does an excellent job of explaining what he did with his code and why he did it.

As you work on Let’s Eat, you’ll have built a professional-looking app that uses a number of iOS features, including GPS and maps, the camera, iPad multitasking, iMessage, and even 3D touch. When you’re done, you should be able to take the knowledge from working on the app and apply it to your own projects.

If learning iOS programming was one of your new year’s resolutions, do yourself a big favor and get your hands on iOS 10 Programming for Beginners. There’s a lot of knowledge packed into this book!

You can get the book from:

{ 0 comments }

Tampa iOS Meetup: The dreaded tip calculator, part 1

by Joey deVilla on February 1, 2017

A new year, a new approach to the meetup, and tweaking the format

Photo by Deanna Gray.

Tampa is lucky to have three iOS meetups. In addition to my group, Tampa iOS Meetup, we’ve got:

Suncoast iOS and Tampa Bay Cocoaheads cover topics better suited for intermediate- to expert-level iOS developers, and they do so quite well. This year, I decided shift the focus of Tampa iOS Meetup towards a different audience: people who were either new to iOS development or who were new to development in general.

With that in mind, the January 2017 session of Tampa iOS Meetup (which took place on Tuesday) was about developing a simple app: a tip calculator. While a tip calculator is a simple application, even the simplest of mobile apps have a lot going on underneath the hood, what with the programming language, the application development framework(s) involved, and the IDE. I covered a fair bit of ground in my presentation, and after a little review, have decided to tweak the format.

Future Tampa iOS Meetups will have two parts:

  • A presentation part, where new concepts are introduced, followed by
  • a workshop part, where those new concepts are applied.

I think that this approach will be more useful, especially to developers who are new to iOS programming or just programming in general. It would give attendees a chance to try out the concepts while they’re still fresh in their minds, as well as a chance for me to help people with their programming.

I’d like to thank Wolters Kluwer for providing the space in which to hold the meetup, as well as the food (excellent salads) and drinks! Special thanks to John Wang, my go-to guy at Wolters Kluwer, and source of valuable feedback for my presentations.

Building the dreaded tip calculator

Let’s start by building a simple app that will grow into the tip calculator. This one will be simple — it will be an app that says “Hi there” when the user taps on a button. Over a couple of articles, we’ll make changes to it, and in the end, it will be a tip calculator.

First step: Create a new project

Start by creating a new iOS project. Launch Xcode, then use File → New → Project…. This will take you to a dialog window where you’ll choose a template, which is a pre-made set of files that you can use as a starting point for your project.

Think of Xcode’s templates as being the coding answer to templates that Office-style apps provide when you create a new document. Just as PowerPoint lets you choose from pre-made templates so you don’t have to design your deck from scratch and have more time to focus on its content…

…Xcode lets you choose from pre-made templates of code, each one designed to be the basis for a different link of app.

Here’s what the “Choose a template for your new project” windows looks like:

In this window, you should:

  • Make sure that iOS is selected in the menu near the top of the window. Xcode can be used to write applications for a number of different platforms, and you want to be certain that the project you create will run on iOS.
  • From the Application section, select Single View Application. This is a template for an app that features a single view, which corresponds to a “screen” in the app. The Single View Application template isn’t just for writing apps with single views; it’s just a template with a single view and its underlying code — a view controller — pre-defined.
  • Click the Next button to go to the next window.

The “Choose options for your next project” window lets you specify a number of options for your project. For this project, we’ll use it to specify a name for your project, leaving the other settings at their default values.

In this window, you should:

  • Enter the name of the app into the Product Name text field. I used Tip Calculator as the name for my app. This will not only be the name of the app, but the name of the folder in which its files will be stored.
  • We’re leaving the other settings at their default values, so click the Next button.

You’ll now be at the screen where you specify where the project should be saved. In this window, you should:

  • Choose a place on your hard drive where your project’s folder will be stored.
  • Make sure that the Create Git repository checkbox is checked, and that My Mac is selected from the drop-down list beside it.
  • Click the Create button, which will start the process of generating the files and folders of your project.

Xcode will spend a moment or two generating your project’s files and folders, after which you’ll be taken to a place where you’ll be spending a lot of time: the Xcode main interface.

Xcode’s main interface is divided into 5 general areas:

  1. The toolbar, which contains a number of frequently-used controls, including those for running or stopping apps, and for changing the layout of the Xcode interface.
  2. The navigators, which take up the left column of the Xcode interface and provide a number of ways of navigating about your project.
  3. The editor area, which occupies the central area of the Xcode interface. It’s where you’ll do a lot of work, including writing code, designing your apps’ user interfaces, and editing your apps’ settings and configurations.
  4. The utilities area, where you can edit the properties and settings of things that you’re working on in the editor area.
  5. The libraries area, which is a repository for user interface controls that you’ll put on your apps’ screens, as well as files, code snippets, and media that you’ll include in your projects.

Right now, we’re going to focus on the toolbar because we’re going to run the app.

Even though you haven’t yet written a single line of code or created a single user interface, you already have a working app. The Single View Application template that your app is using as its basis already contains enough code for an application that will run.

We’ll run the app in the Simulator, which comes with Xcode and can simulate any supported Apple device. It’s useful for quickly testing an app without having to load it onto a device, and handy when you want to test your app on a type of device you don’t have.

To run the app:

  • Select iPhone SE from the menu to the right of the Run (the “play” triangle) and Stop (the “stop” square) buttons in the toolbar. This tells the Simulator to simulate an iPhone SE. It’s one of the smaller-screened iPhones, and as such, it’s good for testing interface designs. If your app is usable on an iPhone SE screen, there’s a very good chance it’ll also be usable on larger-screened devices like the iPhone 6 and 7, and especially the Plus versions.
  • Click the Run button to start the app.

The simulator will take a couple of moments to start up, after which you should see this:

It’s not much to look at, but that’s because we haven’t built a user interface or added any code yet. Now that we’ve confirmed that our template runs, stop the app by clicking the Stop button:

Draw a simple user interface

It’s time to work on our app’s user interface. In order to do this, let’s take a closer look at the left column of the Xcode interface, which is where the navigators live. We’re interested in the Project Navigator, which lets us navigate through all the files that make up a project:

To show the Project Navigator, do the following:

  • Make sure that the Project Navigator is currently displayed. You can do this by clicking on the folder icon from the set of icons located at the top of the left column. The Project Navigator will display a set of files and folders that make up your project. For now, we’re interested only in the files in the Tip Calculator folder.
  • You should be able to see the contents of the Tip Calculator folder — these are files such as AppDelegate.swift, ViewController.swift, Main.storyboard, and so on. If you can’t see them, make them visible by clicking on the disclosure triangle to the left of the Tip Calculator folder.
  • Inside the Tip Calculator folder, you’ll see a file called Main.storyboard. Click on it once; this will cause the main storyboard to appear in the editing area in the center of the screen.

The storyboard is where you draw the user interfaces for the screens (or more accurately, views) of your apps. The term “storyboard” is borrowed from filmmaking; in that field, it’s a way of graphically organizing the scenes of a movie. Here’s an example — an early storyboard for a film that eventually became Star Wars: A New Hope

In Xcode, a storyboard is a way of graphically organizing the views of your app. It’s where we’ll define the user interface of our app, once we’ve done a little housekeeping.

Near the upper right-hand corner of the Xcode interface, you’ll find a set of buttons that determine what the Xcode interface shows. We’ll want to make sure that the both the left and right sidebars are visible:

Do the following:

  • Make sure that the left and right sidebars are visible by ensuring that their buttons (see the screenshot above) are selected. You’ll know that the buttons are selected when they’re highlighted blue. Feel free to click on them to see what happens, just as long as you’ve got the left and right sidebar buttons selected at the end:

Now that we’ve set up Xcode’s sidebars, let’s set up the storyboard so that its views are iPhone SE-sized. Xcode has a feature that makes it easy to design for various screen sizes, and it’s located near the center of the bottom of the Xcode interface:

Do the following:

  • Click on View as: near the center bottom of the Xcode interface. This will cause a menu of various devices to appear. If you hold the cursor over each device’s icon, its name will appear. Select the icon named iPhone SE.
  • In the menu of orientations — located to the right of the menu of devices — choose the portrait orientation.

These steps will cause the storyboard to display iPhone SE-sized views in the portrait orientation.

Now that we’ve set up the view, let’s look at the objects we’ll put into it. Look at the libraries, located near the lower right-hand corner of the Xcode interface:

Of the libraries that are available, we want to make use of the Object Library, which contains user interface objects that we can put on our app’s views. Do the following:

  • Make sure that the Object Library is selected. Click on its icon (the round one), to make sure it’s selected. Feel free to click on the other Library icons to see what happens, just as long as you’ve got Object Library selected at the end.
  • Scroll through the Object Library, where you’ll see all the objects it contains, and their descriptions. When you’re done exploring it, scroll through the list so that you can see the Button object.

It’s time to put user interface items onto the view. The first user interface item is a button:

  • Drag a Button from the Object Library and onto the view. Place it near the upper left-hand corner of the view. As you bring the button close to that corner, Xcode will cause a couple of guides to appear. Line the button up with those guides.

  • Double-click on the button to edit its title. The text in the button will be highlighted, which indicates that you are editing it.

  • Change the text in the button to Tap me.
  • Click anywhere outside the button to stop editing it.

Let’s now add a label, which is a container for read-only text that can neither be selected nor edited by the user:

  • Drag a Label from the Object Library and onto the view. Place it a short distance below the button. As you bring the label close to that view’s left edge, Xcode will cause a guide to appear. Line the label up with that guide, so that its left edge lines up with the left edge of the button.

Since this is a simple app, we’re done drawing its user interface. Time for the next step…

Connecting the interface to the underlying code

Run the app right now, and you’ll see this:

However, if you tap on the Tap me button, nothing happens. In our simple app, we want the text in the label to change to Hi there! when the user taps the Tap me button.

As its name implies, the Single View Application template that we’re building our app on comes with a single view. We just placed a button and label on that view. However, that view doesn’t do very much because we haven’t yet written any code to control that view. This view-controlling code that we’ll write will go into the view controller file, which is very conveniently named ViewController.swift in our project.

We’re going to connect the button and label in our view to the underlying view controller in this step. In order to do this, we’d like to have both the view (which lives the in Main.storyboard file) and the underlying view controller code (which lives in the ViewController.swift file) visible at the same time. This is possible with the Assistant Editor feature, which makes it possible to view two files side by side.

The Assistant Editor button is located near the upper right-hand corner of the Xcode interface. Do this:

  • With the main storyboard visible in the editor area in the center of Xcode, click the Assistant Editor button. Xcode tries to be “smart” about which file you want to edit, and in this case, it should “assume” that you want to look at the app’s only view’s view controller code.

You should see something like the screenshot above. You may want to expand the Xcode window so that it takes up the entire screen.

Let’s connect the button to the view controller code first:

  • Select the Tap me button on the view in the main storyboard, then control-drag (that is, drag while holding down the control key on the keyboard, or if you have a mouse, right-drag) from the view to the ViewController.swift code.
  • Let go of the mouse in the empty spot between
    ViewController: UIViewController {
    and
    override func viewDidLoad() {

A pop-up will appear. This pop-up lets you define the type and details of the connection between a user interface object and the underlying view controller code. There are two types of connection, and we’ll use both in this simple app:

  • Actions: An action is some code that’s run in response to an event. In the case of this app, we’re going to define an action that runs some code when the Tap me is pressed.
  • Outlets: An outlet is a reference to a user interface object, which allows the underlying code to affect that object. In this app, we’ll define an outlet that will allow us to refer to the label, which in turn will allow us to change its text.

Since we’re dealing with the button right now, we’re defining an action connection:

Do the following with the pop-up:

  • Select Action from the Connection menu.
  • Give the action a name: enter buttonPressed into the Name field.
  • Note the default selection in the Event menu, but don’t change it: Touch Up Inside. This is one of the user interaction events that a button can respond to. Touch Up Inside is an event that gets raised when the user pushes down and then releases on a button with their finger still inside the button’s bounds (which is a very precise way of saying “when the user presses the button”).
  • Click the Connect button.

The following code will appear in the view controller:

This is a new method (that’s another term for a function) named buttonPressed, and it will be called whenever the user pressed the Tap me button.

Do the following:

  • To make the code easier to read, add blank lines before and after the newly-created method.

Let’s now define an outlet connection for the label:

  • Select the label on the view in the main storyboard, then control-drag (that is, drag while holding down the control key on the keyboard, or if you have a mouse, right-drag) from the view to the ViewController.swift code.
  • Let go of the mouse in the empty spot between
    ViewController: UIViewController {
    and
    @IBAction func buttonPressed(_ sender: Any) {

Another pop-up will appear:

Do the following with the pop-up:

  • Select Outlet from the Connection menu.
  • Give the outlet a name: enter replyLabel into the Name field.
  • Click the Connect button.

The following code will appear in the view controller:

This is a new variable named replyLabel, and it will be used to access the label in order to change its contents.

Do the following:

  • To make the code easier to read, add blank lines before and after the newly-created variable.

Let’s make it work!

There’s just one thing left to do: write the code that changes the text of the Label to “Hi there!” when the user presses the Tap me button. We already have a method — buttonPressed — that gets called when the button is pressed; all we have to do write the body of that method.

All it takes is one line of code to get what we want. Add the following line to buttonPressed…

…so that the method in its entirety looks like this:

Run the app. It should look like this:

Now press the Tap me button. You should see this:

As you can see, Hi there! got shortened to Hi t…. That’s what happens when a label doesn’t have enough space to accommodate the text it contains. There’s a simple fix…

Do the following:

  • Stop the app.
  • In the main storyboard, select the label. Grab one of the “handles” (the squares that appear around the label) on the right side of the label and use it to widen the label.
  • Run the app.

You should now see the full Hi there! when you press the Tap me button:

Wait, wasn’t this going to be a tip calculator? (or: What’s next?)

After all, the app’s name is Tip Calculator. Don’t worry — in the coming installments in this series, that’s exactly what this app will become. I thought it would be a good idea to start with a simple exercise first, in order to get you comfortable with Xcode and creating simple apps.

In the next article in the series, we’ll look at getting input from the user with text fields.

Download the project files

Although this is an extremely simple project, I’ve made its files available for download — click here to get them!

{ 1 comment }