Warning: count(): Parameter must be an array or an object that implements Countable in /home/iteanz/public_html/wp-includes/post-template.php on line 317

Create a typical iOS application in Swift

You’ll build a simple application with a Submit button, an editable text field, and an output label field.

Create a simple single view application with a graphical user interface (GUI) that includes a text field, a label, and a button.
When the user presses the button, the URL address in the text field is sent to Watson, which analyzes it and returns an opinion that is shown in the output field.

See the Xcode documentation for information about how to create basic GUIs in Xcode.

Connect the GUI in Main.storyboard to the code in the ViewController file:

  1. Double-click TextField (by pressing the mouse pad with two fingers), which contains the URL. Enter this example text:
  2. Select New Reference Outlet from the list. Then, enter urlText in the dialog.
  3. Insert the new reference between class ViewController and override func viewDidLoad.
  4. Click Connect.
    The inserted text is @IBOutlet weak var urlText: UITextField!
  5. Connect the button from the Event Touch Up Inside below the function didReceiveMemoryWarning.
  6. Enter this text in the dialog: analysisButtonPressed
    The inserted text is:
    @IBAction func analysisButtonPressed(sender: AnyObject) {
  7. Connect the text label.
    The result is @IBOutlet weak var analysisTextLabel: UILabel!
  8. Test the code by adding NSLog("url: "+urlText.text!) to the end of the analysisButtonPressed method.
    NSLog allows you to log your actions.
  9. Add analysisTextLabel.text = urlText.text!
    Setting analysisTextLabel.text with urlText.text allows you to show the output from the Text field in the Label field in the UI.
    import UIKit
    class ViewController: UIViewController {
    @IBOutlet weak var urlText: UITextField!
    @IBOutlet weak var analysisTextLabel: UILabel!
    override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.

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

    @IBAction func analysisButtonPressed(sender: AnyObject) {
    NSLog(“button pressed”)
    NSLog(“url: “+urlText.text!)
    analysisTextLabel.text = urlText.text!

    //call service

    //get output


  10. Build and execute your application.