Swift: `respondsToSelector:` always returns `false` when used with generic class
Originator: | hohl.mi | ||
Number: | rdar://19343048 | Date Originated: | 24/12/2014 |
Status: | Open | Resolved: | |
Product: | iOS SDK | Product Version: | iOS 8.1.1, Xcode 6.1.1 |
Classification: | Reproducible: | Always |
Summary: `respondsToSelector` doesn't work with generic classes. Since it seems like UIKit uses `respondsToSelector` internally this can cause crashes when using generic classes in combination with `UIViewController`s or `UITableViewDataSource`. Steps to Reproduce: // with Generics public class ArrayDataSource<T>: NSObject, UITableViewDataSource { ... } var ds = ArrayDataSource<String>() ds.respondsToSelector("tableView:numberOfRowsInSection:") // false // without Generics public class ArrayDataSource2: NSObject, UITableViewDataSource { ... } var ds2 = ArrayDataSource2() ds2.respondsToSelector("tableView:numberOfRowsInSection:") // true Expected Results: `respondsToSelector:` should do its job Actual Results: It just doesn't work, which will also lead to crashes since `respondToSelector:` seems to be used in multiple frameworks. So when you use generic classes with for example UITableView it will lead to an crash. Version: iOS 8.1.1, Xcode 6.1.1 Notes: This issue got found when having troubles with UITableViewDataSource implemented as generic class. See the following StackOverflow question for more details: http://stackoverflow.com/questions/27483560/nsinvalidargumentexception-when-putting-uitableviewdatasource-in-its-own-class/27638112#27638112 Configuration: Seems to be any configuration, tested on iPhone 5 and the Simulator Attachments:
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!