Tuesday, May 16, 2017

How to build an iOS App with the Xcode 8 and Swift 3

Hello developers, In this tutorial I'm gonna show you how to build an iOS App with Xcode.


What is Xcode and Swift ?

     Xcode is a integrated development environment which is developed by apple for developing iOS, macOS, watchOS and tvOS Apps. It comes with iOS SDK, compilers, debugging tools and simulators etc. Install the Xcode app from the Mac App Store itself or download it from here. Note: To install Xcode, you need to have Mac machine.

     Swift is a new programming language developed by Apple Inc and it's release by Chris Lattner in 2010. Swift comes with Playground to write swift program and the outputs are displayed in right pane. It shows the results very fast and you no need to click any run buttons to execute the program. It is very interesting know ? Swift has a lot of features and it has a huge libraries too. The extension of swift program is .swift 

     Okay now let's create our new project and start to build our first iOS App in Xcode.

Creating a Project

  • Open Xcode and Create a new project from the file menu.
  • Select Single View Application template and click Next.
  • Give name to product, organization and organization identifier. See below image for reference.

Adding Views 

  • Click the Main.Storyboard file.
  • Drag and drop the Label and Button from the Object Library into the View. Do like below image.


  • Now open the Assistant Editor in Xcode. Click the double circled icon in top right corner(See the image below) or Click CMD + OPTION + ENTER shortcut.


  • Then drag and drop the label and button into the view controller(viewcontroller.swift file)





  • Then it'll show you one tiny window, in that you've to change the connections and click connect. For button, change the connection from Outlet into Action. For Label, set the connection as Outlets(By default, it's Outlet only) 





View Controller Code

import UIKit

class ViewController: UIViewController {

    @IBOutlet var helloWorldLabel: UILabel!
    
   
    @IBAction func clickMeBtnPressed(_ sender: Any) {
        
        //Setting hello world label into Welcome to iOS World
        helloWorldLabel.text = "Welcome to iOS World"
        
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        print("viewDidLoad function is called")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

Run the App

      Now build the project and run it. Then the app will open in Simulator.




Boom!!! Just click the "Click Me" button then the label will changed from "Hello World" to "Welcome to iOS World". We've completed our first hello world iOS app in Xcode using Swift 3. I hope you guys understand and if you've any doubts in this tutorial then just drop your comments. See you in the next tutorial...

0 comments:

Post a Comment

feel free to post your comments! Don't Spam here!