Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...