Search code examples
iosswiftxcodeunrecognized-selector

Xcode 8.2.1 trying to make app keep getting output errors


I am probably trying to make the easiest app ever but I am unable to get it to work. The the app has two buttons. One that plays a short noise and the other is a donate button. I can get the noise to work but not the link or viceversa or neither. And one of the overrides keeps becoming an error and I dont know why so I put it as a comment so that the app would build. the error that comes up is that it asks me to remove the word override. Here is the code:

import UIKit
import AVFoundation

class ViewController: UIViewController {
    let soundFilenames = ["WeahV2"]
    var audioPlayers = [AVAudioPlayer]()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        // Set up audio player
        for sound in soundFilenames {
            do {
                // Try to do something
                let url = NSURL(fileURLWithPath: Bundle.main.path( forResource: sound, ofType: "mp3")!)
                let audioPlayer = try AVAudioPlayer(contentsOf: url as URL)

                audioPlayers.append(audioPlayer)

            }
            catch {
                //catch the error that is thrown
                audioPlayers.append(AVAudioPlayer())
            }
        }
    }

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

    @IBAction func buttonTapped(_ sender: UIButton) {
        // get the audio player that corresponds with the button tapped
        let audioPlayer = audioPlayers[sender.tag]
        audioPlayer.play()
    }

    @IBAction func Donate( sender: AnyObject) {
        if let url = URL(string: "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=5Q29GRLXF4W9C&lc=CA&item_name=BiBoCo&currency_code=CAD&bn=PP-DonationsBF%3Abtn_donateCC_LG.gif%3ANonHosted") {
            UIApplication.shared.open(url, options: [:]) {
                boolean in
                // do something with the boolean
            }
        }
    }
}

Here is the output information( might be an error for all i know, i dont know how to understand it):

2017-03-08 17:10:34.256692 The Weah[22117:1032077] [aqme] 255: AQDefaultDevice (1): skipping input stream 0 0 0x0
2017-03-08 17:10:36.241162 The Weah[22117:1032029] [aqme] 177: timed out after 0.012s (126 127); suspension count=0 (IOSuspensions: )
2017-03-08 17:10:36.264895 The Weah[22117:1032077] [aqme] 255: AQDefaultDevice (128): skipping input stream 0 0 0x0
2017-03-08 17:10:36.498 The Weah[22117:1030634] -[The_Weah.ViewController Donate:]: unrecognized selector sent to instance 0x7fef9a806b20
2017-03-08 17:10:37.037 The Weah[22117:1030634] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[The_Weah.ViewController Donate:]: unrecognized selector sent to instance 0x7fef9a806b20'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010ca9dd4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010c4ff21e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010cb0df04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x000000010ca23005 ___forwarding___ + 1013
    4   CoreFoundation                      0x000000010ca22b88 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x000000010cec38bc -[UIApplication sendAction:to:from:forEvent:] + 83
    6   UIKit                               0x000000010d049c38 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x000000010d049f51 -[UIControl _sendActionsForEvents:withEvent:] + 444
    8   UIKit                               0x000000010d048e4d -[UIControl touchesEnded:withEvent:] + 668
    9   UIKit                               0x000000010cf31545 -[UIWindow _sendTouchesForEvent:] + 2747
    10  UIKit                               0x000000010cf32c33 -[UIWindow sendEvent:] + 4011
    11  UIKit                               0x000000010cedf9ab -[UIApplication sendEvent:] + 371
    12  UIKit                               0x000000010d6cc72d __dispatchPreprocessedEventFromEventQueue + 3248
    13  UIKit                               0x000000010d6c5463 __handleEventQueue + 4879
    14  CoreFoundation                      0x000000010ca42761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    15  CoreFoundation                      0x000000010ca2798c __CFRunLoopDoSources0 + 556
    16  CoreFoundation                      0x000000010ca26e76 __CFRunLoopRun + 918
    17  CoreFoundation                      0x000000010ca26884 CFRunLoopRunSpecific + 420
    18  GraphicsServices                    0x00000001116eda6f GSEventRunModal + 161
    19  UIKit                               0x000000010cec1c68 UIApplicationMain + 159
    20  The Weah                            0x000000010bbb56bf main + 111
    21  libdyld.dylib                       0x0000000111ce168d start + 1
    22  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Solution

  • When exactly the app stops working?

    Does it happen when you interact with an UI element, like one of the buttons?

    I'm assuming there is a "Donate" button on the UI... Make sure that the connection from the button to the action is correctly wired.

    One of the easiest ways to double-check the wiring is from the interface builder itself.
    Click on the Connections Inspector button:

    Connections Inspector

    Search for any ! sign. If there are any, delete the connection and re-create it.

    If the above doesn't do the trick, please share your project so I can help on debugging it.

    (Regarding the didReceiveMemoryWarning override, you can safely delete it for now.)