-1

I created a function. This function is called by a button. If I press the button the app crashes and throws the following error:

2014-12-23 18:42:59.966 MyApp[8775:115552] -[MyApp.ViewController setDate]: unrecognized selector sent to instance 0x7fbbb9e458a0 2014-12-23 18:42:59.980 MyApp[8775:115552] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyApp.ViewController setDate]: unrecognized selector sent to instance 0x7fbbb9e458a0' *** First throw call stack: ( 0 CoreFoundation 0x000000010451cf35 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000106060bb7 objc_exception_throw + 45 2 CoreFoundation 0x000000010452404d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010447c27c ___forwarding___ + 988 4 CoreFoundation 0x000000010447be18 _CF_forwarding_prep_0 + 120 5 Foundation 0x00000001049512b4 __NSFireTimer + 83 6 CoreFoundation 0x0000000104484f64 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20 7 CoreFoundation 0x0000000104484b25 __CFRunLoopDoTimer + 1045 8 CoreFoundation 0x0000000104447e5d __CFRunLoopRun + 1901 9 CoreFoundation 0x0000000104447486 CFRunLoopRunSpecific + 470 10 GraphicsServices 0x0000000106c289f0 GSEventRunModal + 161 11 UIKit 0x0000000104da8420 UIApplicationMain + 1282 12 MyApp 0x0000000103f6a08e top_level_code + 78 13 MyApp 0x0000000103f6a0ca main + 42 14 libdyld.dylib 0x0000000107834145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

this is the function which is crashing if it's called:

func setDate(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    switch editingStyle {
    case .Delete:
        let appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
        let context:NSManagedObjectContext = appDel.managedObjectContext!
        context.deleteObject(daten[indexPath.row] as NSManagedObject)
        daten.removeAtIndex(indexPath.row)
        context.save(nil)

        self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    default:

        let mySelectedCell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
        mySelectedCell.detailTextLabel?.text = dateLabel.text
        self.sideBar.alpha = 0

        return

    }
}
hom
  • 25
  • 2
  • 6
  • I think you're attempting to call setDate without the proper parameters... – Lyndsey Scott Dec 23 '14 at 17:49
  • 1
    can you show how you are calling? – johny kumar Dec 23 '14 at 17:50
  • I strongly suspect that you have named this method wrong. Are you absolutly sure that it shouldn't be: `func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)`? – Daniel T. Dec 23 '14 at 18:14
  • Note that a method called `setDate`, with no trailing `:`, is very unusual. Almost certainly an error at the call site, failing to provide the parameters. – Hot Licks Dec 23 '14 at 19:04
  • How can I call this function without getting an error? – hom Dec 24 '14 at 23:20

1 Answers1

0

This line tells you everything you need to know:

-[MyApp.ViewController setDate]: unrecognized selector sent to instance 0x7fbbb9e458a0

Your ViewController class doesn't have a method called setDate or a property called date.

As far as I can tell, the function you posted has nothing to do with this error. It never calls setDate.

Daniel T.
  • 32,821
  • 6
  • 50
  • 72
  • It *is* setDate. But the OP's not calling it with the proper parameters apparently... – Lyndsey Scott Dec 23 '14 at 17:56
  • 1
    No, the method he posted is `setDate:commitEditingStyle:forRowAtIndexPath:`. It is not `setDate`. There is a dramatic difference between the two. – Daniel T. Dec 23 '14 at 17:58
  • Yes, that's exactly what I mean. – Lyndsey Scott Dec 23 '14 at 17:59
  • 1
    He/she's trying to call the method but apparently didn't include the parameters. – Lyndsey Scott Dec 23 '14 at 18:00
  • It's worse than that, the name of the method is `setDate:commitEditingStyle:forRowAtIndexPath:` not `setDate`. (Note the lack of a colon in `setDate`. That is a method with no parameters at all. – Daniel T. Dec 23 '14 at 18:16
  • Yes, I'm agreeing with that completely. I'm just disagreeing with this line that you wrote: "As far as I can tell, the function you posted has nothing to do with this error. It never calls setDate." since it's clear the OP was trying to call the posted function...so that's how it's related to the error. – Lyndsey Scott Dec 23 '14 at 18:20
  • I don't think it's so clear that the OP was trying to call that function. I don't think that function is named right (see my comment on the question itself,) and if I'm right about that, then the OP shouldn't be calling the function at all. I think the OP is so confused that (s)he isn't even asking the right question. – Daniel T. Dec 23 '14 at 18:22
  • The OP says, "I created a function. This function is called by a button. If I press the button the app crashes and throws the following error:". So the OP's trying to call the function. – Lyndsey Scott Dec 23 '14 at 18:25
  • 1
    Not that all this back and forth matters... I think the basic issue is pretty clear in this case...that the OP's trying to call a function that doesn't exist... – Lyndsey Scott Dec 23 '14 at 18:26
  • Thanks for your answers! How can I call the function without a crash of the app? – hom Dec 24 '14 at 14:57