swift objective-c bridge compiler warnings
| Originator: | kknauber | ||
| Number: | rdar://17165855 | Date Originated: | 04-Jun-2014 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Version 6.0 (6A215l) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
Bridging swift to objective-c is very painful so far. The compiler is unforgiving about all types including integer types. For example if your obj-c function argument is declared as an (int) instead of an (NSInteger), you'll get a compile error that the function is just not found.
Example: I have this existing objective-c protocol declared in an objc PixelMapUI.h
@protocol DeleteKeyDelegate <NSTableViewDelegate>
- ( void ) deleteKeyPressed: ( NSTableView * ) view onRow: ( int ) rowIndex;
@end
And in my new swift class, I'm trying to do this:
extension NSTableView {
override func keyDown( event : NSEvent ) {
var obj : NSTableViewDelegate = delegate()
var obj2 = obj as? DeleteKeyDelegate;
let characters : NSString = event.characters;
var firstChar = Int(characters.characterAtIndex( 0 ));
// if the user pressed delete and the delegate supports deleteKeyPressed
if ( ( firstChar == NSDeleteFunctionKey ||
firstChar == NSDeleteCharFunctionKey ||
firstChar == NSDeleteCharacter) )
{
if let keyObj = obj as? DeleteKeyDelegate {
keyObj.deleteKeyPressed( self, onRow: selectedRow() );
}
}
}
This produces a compiler error "Could not find member 'deleteKeyPressed'. After stumbling around, I finally changed my obj-c protocol from (int) to (NSInteger) and it started working. ** sigh ** if swift is going to be as unforgiving as f***ing Java, it's not going to be pretty code when every other line of code has a typecast integer.
Steps to Reproduce:
compile code listed above
Expected Results:
- a compile error that suggests a corrective action
- an llvm compiler flag to freely convert between all numeric types
Actual Results:
compiler error "Could not find member 'deleteKeyPressed'"
Version:
Version 6.0 (6A215l)
Notes:
Configuration:
Mac Pro late 2013
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!