Swift: Can't set NSMenuItem target to object that is not NSObject
| Originator: | twealm | ||
| Number: | rdar://21442342 | Date Originated: | 18-Jun-2015 07:13 PM |
| Status: | Open | Resolved: | No |
| Product: | OS X SDK | Product Version: | |
| Classification: | Other bug | Reproducible: | Always |
Summary: In documentation https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSMenuItem_Class/#//apple_ref/occ/instm/NSMenuItem/setTarget: and in header file NSMenuItem has property target, that is defined as weak var target: AnyObject? but if I assign to it object that is not inherited from NSObject, it will crash with *** NSForwarding: warning: object 0x608000000ec0 of class 'CheckMenuSwift.MenuHandler' does not implement methodSignatureForSelector: -- trouble ahead Unrecognized selector -[CheckMenuSwift.MenuHandler methodForSelector:]. Steps to Reproduce: 1. Download attached sample project 2. In AppDelegate.swift file on line 22 change false to true. 3. Run app Expected Results: It should not crash. Actual Results: App crashes. Version: Xcode Version 6.3.2 (6D2105) OS X 10.10.3 (14D136)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Sample code: https://github.com/twealm/rdar-21442342