ios - Swift 3.0 - NSNumber 和 Int 不能应用于操作数

标签 ios swift nsnumber

var Rating = self.currentPerson.Rating

let c = Rating - 1

我正在尝试获取 self.currentPerson.Ratingvalue x 并从 value x 中减去 1。但我只收到下面的错误。

Error : Binary operator '-' cannot be applied to operands of type 'NSNumber' and 'Int'

问题:我该如何解决这个问题?

谢谢

最佳答案

问题已解决。

只需添加 .intValue

var Rating = self.currentPerson.Rating

let c = Rating.intValue - 1

Cred @luk2302

关于ios - Swift 3.0 - NSNumber 和 Int 不能应用于操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41428863/

相关文章:

swift - 在 WatchOS 上的 SwiftUI 应用程序中是否可以进行基于页面的导航?

ios - Swift 中的字符串到 NSNumber

ios - NSUserDefault 字符串无法检索并转换为 double

ios - 如何四舍五入 NSNumber 并在对象 C 中创建一系列数字

ios - 无法为 UIBarButtonItem 设置背景 = UIColor.clearColor()

ios - 如何使用 roundedRect 样式获取 UITextField 的 cornerRadius

ios - "Different language linkage"— xcode 4 中的警告,xcode 5 中的错误

JavaScriptCore 可移植性

ios - UITableViewController 内部 UINavigationController 和 UITabBarController 底部插入关闭

ios - UICollectionView 单元格大小调整