gpt4 book ai didi

ios - Swift 框架 - 在 Objective-C 类中使用 Swift 类引用

转载 作者:行者123 更新时间:2023-11-30 11:06:10 32 4
gpt4 key购买 nike

我正在创建 Swift 框架,其中必须使用 Objective-C 类。所以我经历了this关联。这是我的框架的公共(public) header :

#import <UIKit/UIKit.h>

//! Project version number for Test.
FOUNDATION_EXPORT double TestVersionNumber;

//! Project version string for Test.
FOUNDATION_EXPORT const unsigned char TestVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <Test/PublicHeader.h>

#import <arpa/inet.h>
#import <ifaddrs.h>
#import <netdb.h>
#import <sys/socket.h>
#import <MyTest/MPAppDelegateProxy.h>

现在在MPAppDelegateProxy类中,我必须使用我创建的Swift类。这是:

#import "MPAppDelegateProxy.h"
#import "MyTest.h"

@implementation MPAppDelegateProxy

+ (void)proxyAppDelegate {
[MPGlobal MPLog:@"App delegate not set, unable to perform automatic setup." file:@"MPAppDelegateProxy.m" function:@"proxyAppDelegate" line:32];
// rest of code
}

MPGlobal 是我的 Swift 类之一。但我得到:

Use of undeclared identifier 'MPGlobal'

注意:我在MPGlobal之前添加了@objC

最佳答案

您需要导入<Target>-Swift.h文件。这称为 Objective-C 生成的接口(interface) header 名称。

您可以在目标的build设置中找到它。

enter image description here

该文件由编译器自动生成,需要在 Objective-C 文件中导入。

关于ios - Swift 框架 - 在 Objective-C 类中使用 Swift 类引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52698951/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com