Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

ios - Obj-c extension does not work in swift

Trying to use a obj-c extension in my swift project:

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

Bridging-Header.h

#import "UIBezierPath+hello.h"

Swift

let helloPath = UIBezierPath()
helloPath.hello()

It does build and it does sees the hello method. But it does crush:

-[UIBezierPath hello]: unrecognized selector sent to instance 0x7d2116d0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIBezierPath hello]: unrecognized selector sent to instance 0x7d2116d0'

It seems it does not recognises the implementation. Probably it does not work because I am dumb:) Custom obj-c classes work in swift. Only extension give me this problem

Thanks guys

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

That probably means that you forgot to tick the "Target" checkbox when adding "UIBezierPath+hello.m" to the project, so that the file is not compiled and linked to the executable.

Adding the "Target Membership" in the File inspector should solve the problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...