You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if it was possible to detect 2 types of methods:
If the method has 1 argument, whose name is sender of type id (or AnyObject in Swift), it would be cool to automatically mark this method as @IBAction.
If the method has 1 argument, name doesn't matter, but the type is NSNotifications, make it @objc.
There are many cases where I have forgotten about adding this attribute and then the app crashes when you try to invoke the action or the object receives the notification.
The text was updated successfully, but these errors were encountered:
Hmm... This sounds very interesting. Feel free to post any such cases (and/or with examples) and I'll see what I can do.
In any case, it sure makes sense.
P.S. I'm better though - what can I say - 2016 has already made a strong... impression on me! haha. I don't know what's going on in general, but around here the flu wave is rather... massive...
-(void)_applicationWillTerminate:(NSNotification *)aNotif {
// Do something.
}
// This is usually marked as -(IBAction) in the header file, while in the .m file,
// this is usually void since IBAction is just #define IBAction void.
// sender is id here since we don't need it or it can be called e.g. from both a button
// and a menu item.
-(void)showHelp:(id)sender {
// Do something
}
-(void)save:(NSButton *)sender {
// Do something
}
This should become ideally this:
// Needs to be @objc since it's called via objc_msgSend.
@objc func _applicationWillTerminate(aNotif: NSNotification) {
}
// The same reasoning as before. @IBAction implies @objc, but
// also allows IB to "link" the action. Several notes:
// - sender is optional as per conventions
// - lately, when you create an action from Interface Builder, it allows you to specify
// the object type - e.g. NSButton. In such case the sender should not be optional.
// See the other example.
@IBAction func showHelp(sender: AnyObject?) {
}
// Sender is of a specified type, so it should not be optional and the type
// should be kept as-is.
@IBAction func save(sender: NSButton) {
// Do something
}
Hi, hope you feel better!
I was wondering if it was possible to detect 2 types of methods:
sender
of typeid
(orAnyObject
in Swift), it would be cool to automatically mark this method as@IBAction
.NSNotifications
, make it @objc.There are many cases where I have forgotten about adding this attribute and then the app crashes when you try to invoke the action or the object receives the notification.
The text was updated successfully, but these errors were encountered: