来自< netinet/in.h>的INADDR_LOOPBACK宏;不能迅速导入 [英] INADDR_LOOPBACK macro from <netinet/in.h> not imported in swift

查看:198
本文介绍了来自< netinet/in.h>的INADDR_LOOPBACK宏;不能迅速导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用没有文档的peertalk框架. 在他们的obj-c示例中,他们使用INADDR_LOOPBACK宏,并且示例正在运行. 但是,当我尝试快速执行相同操作时,系统抛出一个无法解析的标识符错误. 有人知道如何解决吗?

I'm trying to use the peertalk framework which has no documentation. On their obj-c example they use the INADDR_LOOPBACK macro, and example is working. But when i try to do the same in swift the system throw me an unresolved identifier error. Anyone knows how to fix it?

http://www.gnu. org/software/libc/manual/html_node/Host-Address-Data-Type.html

推荐答案

针对Swift 3的更新:从Swift 3开始,INADDR_LOOPBACK 被导入到Swift中.因此,添加

Update for Swift 3: As of Swift 3, INADDR_LOOPBACK is imported into Swift. Therefore it suffices to add

#include <netinet/in.h>

到桥接头文件,但不是自定义定义 不再需要了.

to the bridging header file, but a custom definition is not needed anymore.

旧答案:出于某种原因,宏定义

Old answer: For some reason, the macro definition

#define INADDR_LOOPBACK         (u_int32_t)0x7f000001

中的

不是 导入到Swift中. 问题可能(u_int32_t)强制转换,因为 其他宏

from <netinet/in.h> is not imported into Swift. The problem might be the (u_int32_t) cast, because other macros like

#define INADDR_NONE             0xffffffff              /* -1 return */

已导入.

一种解决方案是定义

let INADDR_LOOPBACK = UInt32(0x7f000001)

在您的Swift代码中. 或者,添加

in your Swift code. Alternatively, add

#include <netinet/in.h>
const uint32_t kInAddrLoopback = INADDR_LOOPBACK;

到桥接头文件,并在Swift代码中使用kInAddrLoopback. 这不太容易出错,因为您不必重复常数.

to the bridging header file and use kInAddrLoopback in the Swift code. This is less error-prone because you don't have to repeat the constant.

这篇关于来自&lt; netinet/in.h&gt;的INADDR_LOOPBACK宏;不能迅速导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆