Swift和Objective C委托调用 - 数据类型问题

时间:2015-07-30 19:39:12

标签: objective-c swift types delegates int

我尝试在Objective C中使用Swift类,让Objective C类“GameScene”接收来自swift类的委托调用。但是从swift类中我得到错误“无法调用带有类型'的参数列表的drawTopEdge(int,col:int)'

    //above in the code
    var maze:[[Int]]!
////////////////
     func display() { //this is in the swift class
        for i in 0..<y {
            // Draw top edge
            for j in 0..<x {
                print((maze[j][i] & 1) == 0 ? "+---" : "+   ")
                if ((maze[j][i] & 1) == 0) {
                   delegate!.drawTopEdge(j, col: i) //Error see picture attached and above
                }
            }


    //This is in the GameScene class
    -(void)drawTopEdge:(NSUInteger)r col:(int)c; 
    -(void)drawLeftEdge:(NSUInteger)r col:(int)c;
    -(void)drawBottomEdge:(NSUInteger)r col:(int)c;

http://i.stack.imgur.com/dVLEe.png

enter image description here

1 个答案:

答案 0 :(得分:0)

-(void)drawTopEdge:(NSUInteger)r col:(int)c; 

NSUInteger在Swift中变为Int。但是,int变为CInt。理想情况下,您应该更改签名以使用基于NS*的整数,以便Swift可以轻松地桥接它们。但除此之外,你可以在调用点进行投射:

delegate!.drawTopEdge(j, col: CInt(i))

有关详情,请参阅Dealing with C APIsFoundation Data Types