[Swift 1] Day 2 - Xcode, Auto Layout, and Code


Watch the Day 2 Introduction Video

Day 2 is focused on Xcode and will introduce:

  1. Panels and Xcode buttons
  2. Xcode files (Code, UI, Images, settings)
  3. App Flow (Where does an app start, where do you place code)
  4. Calculator style app UI design
  5. Auto Layout for iPhone apps
  6. Text input from the user

Code Exercise:

  • Work with user input containing floating point values (3.14) i.e. Double and Float in Swift

Again I appreciate your support and I’ve been monitoring the discussions, but I haven’t had the time yet to participate fully.


PS Let me know if you have any feedback on the Day 1 materials in terms of flow, difficulty, and clarity.


I get the question “Do you want the application “Xcode.app” to accept incoming network connections?”.
Is this safe to allow? What is this for?


Yes. It seems like it’s related to your firewall or security settings.

Did you download Xcode 6 from the App Store after iOS 8 was released?



Yes, I did download Xcode 6 after iOS 8 was released, but never allowed incoming network connections to it. Xcode is now on my firewall’s list of applications that allows incoming connections, so I shouldn’t get the message anymore.

Thank you.



Here is my solution for Day 2 exercise - not sure if this is the most efficient or more-Swift way of doing it but it seems to work.

@IBAction func buttonPressed(sender: AnyObject) {
    println("Button was pressed")
    var widthString = NSString(string: widthTextField.text)
    var heightString = NSString(string: heightTextField.text)
    var widthDouble : Double? = widthString.doubleValue
    var heightDouble : Double?  = heightString.doubleValue
    if (widthDouble != nil && heightDouble != nil) {
        println("valid input - width= \(widthDouble) and height = \(heightDouble)")
        var area = widthDouble! * heightDouble!
        outputLabel.text = "\(area)"


Day 2 quick feedback:

Short videos: +1

Much better to concentrate. :smile:


Hi Paul,
just a quick word to let you know I love your lessons. I do have to pause the video quite often to write some code and catch up, but I think this is the way to go so everyone can do the lesson at their own pace. I found the Day 2 exercise challenging, I tried a bunch of code before finding something that worked, but was very happy when I did found a solution. I think it could be nice to have some quick feedback from you in the Q&A the next day, just a minute or 2 where you could tell us what was the most efficient approach and why. Thanks again.



There are many approaches. Depending on the complexity, I might provide a solution, but many of the posted code examples seem to provide enough direction.

At the end of the day, the naive approach is always best. It doesn’t have to be the fastest, it just needs to get the job done.

Fight less battles and get something working, that way you’ll be able to ship an app.


Hi Paul

I’m only just getting started from day 1, and am at Day 2, I’m not sure if the Area Calculator code is available somewhere to download or should I just pause the video and type it in?


Great work Greg!

Type in the code, that’s the best way to learn. Going through the motions is going to help, because you’ll write buggy code and then learn how to fix it. It’s all part of the learning process.

Below each video, there should be a download for the source code.


Hi Paul

I’m having some trouble working on my XCode file. See I started it at my home computer, made all the steps (dragged all my label elements and so on in the main.storyboard file, wrote the code in the viewController.swift) and worked just fine.
I’m saving my files in a Dropbox folder, so my work computer is always synced.
Now, in my work computer I can’t seem to open the storyboard file, I keep getting an empty storyboard area, while the .swift file is as it should (by the way, the app is working in the iOS Simulator just fine)

The storyboard file looks like this: http://d.pr/i/g1RI

You may notice that in the document outline (in the left) the View elements are greyed out (plus the dimensions of the screen on the storyboard is not what I chose when I made it…

Any ideas why this is happening? Haven’t had any problems with dropbox syncing so far in any of my work files.

Thanks in advance


Oops… I was quick to post my question!
Just watched the video: 2.11 Bug Fixes - Size Classes for Compact Any
and it explained exactly the bug I was facing…

Sorry about that!


Glad you figured it out!


I am following day 2 lessons and I just cant bring up the drag and message for the constraints. When i try and follow video 2.6 at 2 mins 50 in where you re adding in constraints, if i click and drag it moves the whole label rather than giving me the option box to put in a horizontal constraint. What am i doing wrong? I know i am tired but could use some help on this small point. Thanks in advance.


You need to right-click your mouse and drag.

Or on trackpad you need to two finger click and drag.


I feel dumb, thanks for the answer though. Note to self past midnight isn’t a good time for clear thinking and studying :frowning:


create two TextField and a label the sum of them when we connect, when we run the application, the button the sum of numbers that can be entered without the need for automatic How do we do it?


@asdrt what is your question?

Can you please rephrase what you’re trying to do?


Enter the numbers on the label are made automatically when transactions

Firefish: Sınav
(As the second page of the screen image)
smilar to…


Ok, using text as it is typed is covered in Day 11.2 Tutorial.