gpt4 book ai didi

Swift 编译器错误?不能使用 "direct"作为方法名称

转载 作者:可可西里 更新时间:2023-11-01 00:58:15 25 4
gpt4 key购买 nike

有人可以请我对此进行理智检查吗?我用三个小文件制作了一个 Swift3/Obj-C 项目*:

ChannelSpy.swift :

import Foundation  
class ChannelSpy: RMQChannel {
func direct(_ name: String!) {}
}

RMQChannel.h :

#import <Foundation/Foundation.h>  
@protocol RMQChannel
- (void) direct:(NSString *)name;
@end

桥接头.h :

#import "RMQChannel.h"

但这不会编译!这是我收到的错误:
类型“ChannelSpy”不符合协议(protocol)“RMQChannel”
协议(protocol)需要类型为“(String!) -> Void”的函数“dirent”;你想添加 stub 吗?

/Proj/. . ./ChannelSpy.swift:2:7: error: type 'ChannelSpy' does not conform to protocol 'RMQChannel'  class ChannelSpy: RMQChannel {        ^  __ObjC.RMQChannel:2:17: note: protocol requires function 'dirent' with type '(String!) -> Void'; do you want to add a stub?      public func dirent(_ name: String!)                  ^  

这是什么“dirent”东西?我(或 Rabbit* 项目)不允许使用名称“direct”吗?我用谷歌搜索了这个(当然是广泛搜索),我在古老的 BSD 代码残余中看到了 #define direct dirent 的痕迹,但我确信这与任何事情都无关。

* - 实际上我正在尝试构建 RabbitMQ Client ,同时将其移植到 Swift 3 和 OS X(官方不支持)。也就是说,测试是用 Swift 编写的,而 Rabbit 库本身仍然是 Objective-C。为了其他需要在 OS X 上使用 RabbitMQ 的人的利益,我正在将我的分支检查到 GitHub。

最佳答案

系统包含文件<sys/dir.h>定义:

/*
* Backwards compatibility.
*/
#define direct dirent

我不知道这个定义有什么用,但显然 <sys/dir.h>包含(间接)来自 Foundation.h , 以便 directdirent 取代在所有(目标)C 代码中。

因此协议(protocol)暴露给 Swift 作为

public protocol RMQChannel {
public func dirent(_ name: String!)
}

如果无法重命名属性,则 undef调用宏(包括系统 header 之后)应该是一个可行的解决方法:

#undef direct
@protocol RMQChannel
- (void) direct:(NSString *)name;
@end

关于Swift 编译器错误?不能使用 "direct"作为方法名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39980671/

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