使用 Swift 1.2(是的,我还没有切换到 Xcode 7,这让我很伤心),我有以下表格视图委托方法:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.coreDataSource.numberOfRowsInSection(section)
}
这会导致 Xcode 6.4 给出错误:
无法使用“(Int)”类型的参数列表调用“numberOfRowsInSection”
我从 Objective-C 桥接的 CoreDataSource 方法具有以下 .h 声明:
- (NSUInteger) numberOfRowsInSection: (NSUInteger) section;
如果我在我的表视图委托方法中应用 UInt 强制:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.coreDataSource.numberOfRowsInSection(UInt(section))
}
Xcode 现在给出错误:
'UInt' 不能转换为 'Int'
所以,如果你这样做,它看起来就像是被诅咒的,如果你不这样的场景,它看起来是被诅咒的。
从Apple 的文档中,他们说:
Swift 将 NSUInteger 和 NSInteger 连接到 Int。
想法?