在Swift 1.2中(没错,我还没换到引起我烦恼的Xcode 7),我有以下的表视图代理方法:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.coreDataSource.numberOfRowsInSection(section)
}
导致Xcode 6.4报错:
无法使用类型为'(Int)'的参数列表调用'numberOfRowsInSection'
我的CoreDataSource方法是从Objective-C桥接过来的,具有以下.h声明:
- (NSUInteger) numberOfRowsInSection: (NSUInteger) section;
如果我在我的表格视图代理方法中应用UInt强制转换:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.coreDataSource.numberOfRowsInSection(UInt(section))
}
现在Xcode出现了以下错误信息:
'UInt' 无法转换为 'Int'看起来是一种进退两难的情况。
根据苹果文档中所说,Swift将NSUInteger和NSInteger桥接到Int。
你有什么想法吗?
Int
中吗(返回Int(self.coreDataSource…)
)? - Aaron Brager