二元算子<不能在Swift中应用于Clong

时间:2015-11-30 21:12:12

标签: swift

我正在尝试在swift中实现以下代码。但是我的i变量拒绝与我的MAXADDRS交谈。它在Swift中说binary operator < cannot be applied to Clong。如果我使用CInt问题就会消失,但是当我在i

时,我会在变量theAddr = ip_addrs[i]上收到错误
   InitAddresses();
   GetIPAddresses();
   GetHWAddresses();
   var i = CLong()
            var deviceIP = NSString()
            for (i=0; i < MAXADDRS; ++i)
            {
                var localHost = 0x7F000001;        // 127.0.0.1
                var theAddr = CLong()

                theAddr = ip_addrs[i]

                if (theAddr == 0) {return}
                if (theAddr == localHost){continue}

                NSLog("Name: %s MAC: %s IP: %s\n", if_names[i], hw_addrs[i], ip_names[i]);

                //decided what adapter you want details for
                if (strncmp(if_names[i], "en", 2) == 0)
                {
                    NSLog("Adapter en has a IP of %s", ip_names[i]);
                }
            }


            // Do any additional setup after loading the view, typically from a nib.
        }

它打算比较的MAXADDRS与以下OBC标题相关

这里的源文件

http://www.chrisandtennille.com/code/IPAddress.h http://www.chrisandtennille.com/code/IPAddress.c

我的桥接标题

#include "IPAddress.h"
#include "IPAddress.c"

1 个答案:

答案 0 :(得分:1)

#define MAXADDRS    32

的形式导入Swift
public var MAXADDRS: Int32 { get }

另一方面,CLongInt的别名(“C'long'类型。”) 因此,您需要将所有值转换为通用类型。以来 数组下标需要Int索引,转换MAXADDRSInt可能是最简单的解决方案:

var i = 0 // Int
for (i=0; i < Int(MAXADDRS); ++i) {

}

或更简单:

for i in 0 ..< Int(MAXADDRS) {

}