我尝试在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;
答案 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 APIs和Foundation Data Types。