-3

I am creating my first iOS application in Xcode Version 11.4.1 (11E503a). I am using Swift 5.1 and Storyboard for User Interface construction. I am having five TextFields in a single view app. The user is supposed to input data in these fields, and then there is a send button. When the user will push the send button the data in the fields shall be saved in a dictionary. I am suspecting that is the part where I am doing something wrong. I am not sure about the nature of the error when I am running this program in an emulator. The following is the code, I have written in ViewController.swift

import UIKit

class ViewController: UIViewController {


@IBOutlet weak var SerialNumber: UITextField!

@IBOutlet weak var WastebinType: UITextField!

@IBOutlet weak var EnterStatus: UITextField!

@IBOutlet weak var ActionRequired: UITextField!

@IBOutlet weak var EnterZone: UITextField!

@IBOutlet weak var SendButton: UIButton!



    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

    }


    @IBAction func SendTapped(_ sender: Any) {

        self.SaveFields()
        }

    func SaveFields(){   // This function is creating a dictionary of the data entered in the
        let SN = self.SerialNumber.text!            // text field
        let WT = self.WastebinType.text!
        let ER = self.EnterStatus.text!
        let AR = self.ActionRequired.text!
        let EZ = self.EnterZone.text!

        let dict = ["SN": SN, "WT": WT, "ER" : ER, "AR" : AR, "EZ" : EZ]

         print("/(dict)")
        }

}

The following is the error message I am getting in the console :

2020-05-04 23:30:24.164409+0530 Garbage management[8811:544439] -[Garbage_management.ViewController SendTap:]: unrecognized selector sent to instance 0x7fc9e550a2c0
2020-05-04 23:30:24.179445+0530 Garbage management[8811:544439] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Garbage_management.ViewController SendTap:]: unrecognized selector sent to instance 0x7fc9e550a2c0'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23e39f0e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff50ad79b2 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23e5ac34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   UIKitCore                           0x00007fff48bf7058 -[UIResponder doesNotRecognizeSelector:] + 302
    4   CoreFoundation                      0x00007fff23e3e90c ___forwarding___ + 1436
    5   CoreFoundation                      0x00007fff23e40bf8 _CF_forwarding_prep_0 + 120
    6   UIKitCore                           0x00007fff48bc9235 -[UIApplication sendAction:to:from:forEvent:] + 83
    7   UIKitCore                           0x00007fff4857a9d3 -[UIControl sendAction:to:forEvent:] + 223
    8   UIKitCore                           0x00007fff4857ad1b -[UIControl _sendActionsForEvents:withEvent:] + 396
    9   UIKitCore                           0x00007fff48579c8c -[UIControl touchesEnded:withEvent:] + 497
    10  UIKitCore                           0x00007fff48c04a70 -[UIWindow _sendTouchesForEvent:] + 1359
    11  UIKitCore                           0x00007fff48c067f5 -[UIWindow sendEvent:] + 4501
    12  UIKitCore                           0x00007fff48be0c39 -[UIApplication sendEvent:] + 356
    13  UIKitCore                           0x00007fff48c6b096 __dispatchPreprocessedEventFromEventQueue + 7328
    14  UIKitCore                           0x00007fff48c6e262 __handleEventQueueInternal + 6565
    15  UIKitCore                           0x00007fff48c64dcb __handleHIDEventFetcherDrain + 88
    16  CoreFoundation                      0x00007fff23d9deb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    17  CoreFoundation                      0x00007fff23d9dddc __CFRunLoopDoSource0 + 76
    18  CoreFoundation                      0x00007fff23d9d5b4 __CFRunLoopDoSources0 + 180
    19  CoreFoundation                      0x00007fff23d981ae __CFRunLoopRun + 974
    20  CoreFoundation                      0x00007fff23d97ac4 CFRunLoopRunSpecific + 404
    21  GraphicsServices                    0x00007fff38b2fc1a GSEventRunModal + 139
    22  UIKitCore                           0x00007fff48bc7f80 UIApplicationMain + 1605
    23  Garbage management                  0x000000010081d4ab main + 75
    24  libdyld.dylib                       0x00007fff519521fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Kindly help me to understand the nature of this error, why is it arising, and how to mitigate it.

Sayantan4796
  • 169
  • 1
  • 10

1 Answers1

1

Just rename your action to

@IBAction func SendTap(_ sender: Any) {
    self.SaveFields()
}

Most probably you made connection from storyboard and then rename it in editor, which, of course, did not rename it automatically back in storyboard.

Asperi
  • 228,894
  • 20
  • 464
  • 690
  • I followed your instructions, the same error is appearing. But still Thanks for your help. – Sayantan4796 May 04 '20 at 18:30
  • I know what you mean now, you want me to delete the IBAction code entirely and break the connection too and then make a new one. Got it. Thanks. – Sayantan4796 May 04 '20 at 18:35