首页 > obc与swift函数转化问题

obc与swift函数转化问题

我在做项目的时候遇到了objective-c中有这样的函数
- (NSString *)menu:(DOPDropDownMenu *)menu titleForRowAtIndexPath:(DOPIndexPath *)indexPath
{


}
然后我作了桥接,想用swift写这个函数,但是我不知道怎么转化,请大神告诉我上面的obc的意思与如何转化,谢谢


func menu(menu:DOPDropDownMenu,titleForRowAtIndexPath indexPath:DOPIndexPath) -> NSString{

}

1.func 前面加不加private取决于想不想暴露在外面使用
2.Swift中一般都是用String取代NSString,他们之间的转换可以用 as String 和 as NSString来完成
3.此写法是参照tableview的方法写的,括号里面是参数, -> 后面是返回值类型,如下:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return myCellArray.count
    }
    
    
【热门文章】
【热门文章】