0

I am trying to learn iOS app development in Swift following this developer.apple tutorial but am getting lost. I am a moderately experienced coder (without any experience with GUI) but I think I am being confused by the Xcode interface.

I am trying to test the following extremely simple app that I've built following the above tutorial

//
//  ViewController.swift
//  test
//
//  Created by Remi on 2017-07-29.
//  Copyright © 2017 Remi. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    //MARK: Properties
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var mealNameLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

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

    //MARK: Actions
    @IBAction func setDefaultLabelText(sender: UIButton) {
        mealNameLabel.text = "Default Text"
    }
}

When I run this code I get an error signal SIGABRT at the lign class AppDelegate: UIResponder, UIApplicationDelegate { of AppDelegate.swift

Here is the output on the console

2017-07-31 09:15:56.334 test[78397:35616616] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<test.ViewController 0x7fdf1bb0f770> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key setDefaultLabelText.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010fd26e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000111a66deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010fd26aa9 -[NSException raise] + 9
    3   Foundation                          0x00000001100ef9bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
    4   UIKit                               0x00000001106d2320 -[UIViewController setValue:forKey:] + 88
    5   UIKit                               0x0000000110900f41 -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x000000010fc674a0 -[NSArray makeObjectsPerformSelector:] + 224
    7   UIKit                               0x00000001108ff924 -[UINib instantiateWithOwner:options:] + 1864
    8   UIKit                               0x00000001106d8eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    9   UIKit                               0x00000001106d9816 -[UIViewController loadView] + 178
    10  UIKit                               0x00000001106d9b74 -[UIViewController loadViewIfRequired] + 138
    11  UIKit                               0x00000001106da2e7 -[UIViewController view] + 27
    12  UIKit                               0x00000001105b0ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61
    13  UIKit                               0x00000001105b1199 -[UIWindow _setHidden:forced:] + 282
    14  UIKit                               0x00000001105c2c2e -[UIWindow makeKeyAndVisible] + 42
    15  UIKit                               0x000000011053b663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
    16  UIKit                               0x0000000110541cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
    17  UIKit                               0x000000011053ee7b -[UIApplication workspaceDidEndTransaction:] + 188
    18  FrontBoardServices                  0x00000001138fb754 -[FBSSerialQueue _performNext] + 192
    19  FrontBoardServices                  0x00000001138fbac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    20  CoreFoundation                      0x000000010fc52a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    21  CoreFoundation                      0x000000010fc4895c __CFRunLoopDoSources0 + 556
    22  CoreFoundation                      0x000000010fc47e13 __CFRunLoopRun + 867
    23  CoreFoundation                      0x000000010fc47828 CFRunLoopRunSpecific + 488
    24  UIKit                               0x000000011053e7cd -[UIApplication _run] + 402
    25  UIKit                               0x0000000110543610 UIApplicationMain + 171
    26  test                                0x000000010fb4846d main + 109
    27  libdyld.dylib                       0x000000011256f92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Can you help me out understand what is going on here?


I am using Xcode Version 7.2.1

Remi.b
  • 17,389
  • 28
  • 87
  • 168

3 Answers3

2

Check your action method carefully,

 @IBAction func setDefaultLabelText(sender: UIButton) {
        mealNameLabel.text = "Default Text"
    }

It may not be connected to your view controller in storyboard.

To check:

  1. Go to the main.storyboard and

enter image description here

Right click on first tap here button then you see the yellow warning icon, It means it not connected to your setDefaultLabelText. Connect them using the Assistant Editor.

Saurabh Jain
  • 1,688
  • 14
  • 28
1

You may have deleted the class name of viewcontroller on uistoryboard. please check this image for referenceenter image description here

Sourabh Shekhar
  • 157
  • 1
  • 12
0

I think you deleted something them reinserted it. go to the main storyboard and right click on the yellow part of the view controller. if there is a yellow hazard symbol delete it

Gurpinder Singh
  • 43
  • 1
  • 1
  • 12
  • This isn't an answer, it's a comment. You gave extremely little details on correcting it - and absolutely no details on what the real issue is. Please, refrain from posting answers that do not help others. Thanks. –  Jul 31 '17 at 16:34
  • it actually is an answer as it shows exactly that the mistake was that he deleted a connection and recreated it and to solve it he should "go to the main storyboard and right click on the yellow part of the view controller. if there is a yellow hazard symbol delete it." @dfd – Gurpinder Singh Jul 31 '17 at 17:32
  • Check the answer by @GurpinderSingh - that answer is helpful, not only to the OP, but to others. Stating that "I think..." and not even explaining - in detail - why is what is considered a "low quality" answer here. I understand you do not have enough rep points to comment, but what you gave for an answer was worth only as a comment. Edit your answer to give more of an explanation and you have a much better answer! –  Jul 31 '17 at 17:45