[英]Swift Framework <-> ObjC interoperation
I've got a dylib framework with some UIView subclasses made in swift which I've done to use the new @IBDesignable
and @IBInspectable
stuff. 我有一个dylib框架,其中包含一些在swift中创建的UIView子类,我已经完成了使用新的
@IBDesignable
和@IBInspectable
东西。
So lets say I've got a UITextField
subclass in there named MyTextField.swift
like this: 所以我要说我有一个名为
MyTextField.swift
的UITextField
子类,如下所示:
MyTextField.swift MyTextField.swift
@IBDesignable class MyTextField: UITextField {
// some properties etc.
// content is irrelevant
}
Now it compiles and works well in InterfaceBuilder so far so good. 现在它在InterfaceBuilder中编译并运行良好到目前为止都很好。 But what I need to do is import this special subclass into my Objective C implementation of the controller to set a property in code at runtime.
但我需要做的是将这个特殊的子类导入到控制器的Objective C实现中,以便在运行时在代码中设置属性。
The framework (named myViews
) has a header called myViews.h
which I am able to import into the controllers header like this: 框架(名为
myViews
)有一个名为myViews.h
的标头,我可以将其导入控制器标头,如下所示:
MyViewController.h: MyViewController.h:
@import myViews;
#import <UIKit/UIKit.h>
#import "myViews.h"
@interface MyViewController : UIViewController
@property(weak, nonatomic) IBOutlet MyTextField *txtName; // <-- This is the problem!
@end
This is where I'm stuck! 这就是我被困住的地方! So the class
MyTextField
is unknown from the imported headers. 因此,导入的标头中的
MyTextField
类是未知的。 The myViews.h
was automatically generated. myViews.h
是自动生成的。 I've tried to import the bridging-headers in there without success. 我试图在那里导入桥接头没有成功。
myViews.h: myViews.h:
#import <UIKit/UIKit.h>
//! Project version number for myViews.
FOUNDATION_EXPORT double myViewsVersionNumber;
//! Project version string for myViews.
FOUNDATION_EXPORT const unsigned char myViewsVersionString[];
// In this header, you should import all the public headers of your framework
// using statements like #import <myViews/PublicHeader.h>
#import <myViews/MyTextField-Swift.h> // <-- This is what I've tried to import here which doesn't work as well.
Hope anybody may help me out. 希望有人可以帮助我。 Thanks in advance.
提前致谢。
In your objective-c class, try importing your swift module like this: 在您的objective-c类中,尝试导入您的swift模块,如下所示:
#import "<ModuleName>-Swift.h"
Where ModuleName is the name of the module containing the swift code 其中ModuleName是包含swift代码的模块的名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.