Obj-c扩展不能快速工作

试图在swift项目中使用obj-c扩展名:

UIBezierPath + hello.h

#import <UIKit/UIKit.h> @interface UIBezierPath(hello) - (void)hello; @end 

UIBezierPath + hello.m

 #import "UIBezierPath+hello.h" @implementation UIBezierPath(hello) - (void)hello { NSLog (@"hello hello"); } @end 

转职Header.h

 #import "UIBezierPath+hello.h" 

迅速

 let helloPath = UIBezierPath() helloPath.hello() 

它确实build立,它确实看到了hello方法。 但它确实暗恋:

– [UIBezierPath hello]:无法识别的select器发送到实例0x7d2116d0 ***终止应用程序由于未捕获的exception'NSInvalidArgumentException',原因:' – [UIBezierPath hello]:无法识别的select器发送到实例0x7d2116d0'

看来它不承认实施。 可能它不工作,因为我很笨:)自定义obj-c类在swift中工作。 只有扩展给我这个问题

多谢你们

这可能意味着在向项目添加“UIBezierPath + hello.m”时忘记勾选“目标”checkbox,以便文件不会被编译并链接到可执行文件。

在文件检查器中添加“目标成员资格”应该可以解决问题。