Charlesism Charlesism - 1 year ago 96
Objective-C Question

Swift extension "Method definition not found"

I'm writing a Swift extension to my ObjC class. Although my code compiles and runs perfectly, I'm getting a bunch of Xcode warnings (one per every Swift method):

"Method definition for 'foo_method:' not found"
"Method definition for 'bar_method:' not found"
"Method definition for 'baz_method:' not found"

It's dead simple to reproduce the Xcode message. I made this demo project with four lines of non-boilerplate code:

Objective-C (subclass of NSView)

// Subclass_of_NSView.h

#import <Cocoa/Cocoa.h

@interface Subclass_of_NSView : NSView


// Subclass_of_NSView.m

@implementation Subclass_of_NSView

- (instancetype)initWithFrame:(NSRect)frame
//______________^ WARNING: Method definition for resizeSubviewsWithOldSize: not found
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
return self;


Swift (extends the Obj-C subclass)

// Extension_of_Subclass.swift

import Foundation

extension Subclass_of_NSView {

override func resizeSubviewsWithOldSize( old_bounds_size:NSSize ) {




// Demo_Project-Bridging-Header.h

#import "Subclass_of_NSView.h"

I'm guessing the warnings would go away if I either:

a) create a bunch of dummy methods in the .m file of my ObjC class.

b) in my Swift extension, extend my ObjC class's superclass.

I don't love either of these solutions.

Is there a better way to make the compiler happy?

Answer Source

I'm not sure what's going on here, I think the problem is something to do with how NSView is bridged to the swift language.

If you're going to override those methods, make sure you call the super implementation, since NSView will probably break spectacularly without them. However I'm not sure if even this is safe, you might still break NSView — perhaps the reason the errors occur is because of some weird/non-standard setup Apple is doing.

If I was you, I'd just put up with the compiler warnings, and report the issue to Apple via Hopefully it will be fixed in a future beta release of Xcode 6.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download