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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...