首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在SWIFT 3中如何使用NSNumber&Integer?

在SWIFT 3中如何使用NSNumber&Integer?

提问于 2018-01-31 00:54:48
回答 2关注 0查看 738

我正在尝试将我的项目转换为SWIFT 3.0,但是在使用NSNumberIntegers...

不能将int类型分配给nsnumber类型

代码语言:txt
复制
//item is a NSManaged object with a property called index of type NSNumber 

var currentIndex = 0
 for item in self.selectedObject.arrayOfItems {
   item.index = currentIndex
   currentIndex += 1
 }

即使我改变了currentIndex到某一类型NSNumber然后我得到错误

Binary operator '+=' cannot be applied to type 'NSNumber' and 'Int'

所以我创建了一个名为one类型NSNumber添加到currentIndex然后得到以下错误;

Binary operator '+=' cannot be applied to two NSNumber operands

&&我得到的第二个错误是

No '+' candidates produce the expected contextual result type NSNumber

代码语言:txt
复制
 let num: Int = 210
 let num2: Int = item.points.intValue
 item.points = num + num2

这里我只是想把210加到PointProperty,itemNSManagedObject...

所以基本上,我有问题,让我的头脑在添加数字类型的属性。NSNumber.我在工作NSNumber因为它们是NSManagedObject他的。

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档