Ios (国际)——>$T4与NSMutableArray不同
我的问题被问为题目。让我来描述一下Ios (国际)——>$T4与NSMutableArray不同,ios,swift,Ios,Swift,我的问题被问为题目。让我来描述一下 我声明了NSMutableArray的一个实例,它调用items,并将20分配给它的容量 var items=NSMutableArray() items=NSMutableArray(容量:20) 我在应用程序中使用了UICollectionView,UICollectionView的委托方法出现错误 func collectionView(collectionView:UICollectionView!,moveItemAtIndexPath fromIn
items
,并将20
分配给它的容量
var items=NSMutableArray()
items=NSMutableArray(容量:20)
func collectionView(collectionView:UICollectionView!,moveItemAtIndexPath fromIndexPath:NSIndexPath!,toIndexPath:NSIndexPath!){
变量thing:NSString=items(fromIndexPath.item)
self.items.removeObjectAtIndex(fromIndexPath.item)
self.items.insertObject(thing,atIndex:toIndexPath.item)
}
方法的第三行,var thing:NSString=items(fromIndexPath.item)
,返回一个错误--(Int)->$T4与NSMutableArray不相同
请告诉我如何解决它
非常感谢您的时间和指导
伊桑·乔我建议使用强类型的本机Swift字符串数组:
var items:[String] = []
此外,从数组中检索时需要使用方括号:
let thing = items[fromIndexPath.item]
输入错误,使用方括号从数组中检索:
var thing:NSString=items[fromIndexPath.item]
感谢您回答我的问题。你的回答解决了我的问题。它仍然需要在代码末尾添加'as NSString'。投票结束了这个输入错误抱歉,我是一个新的堆栈溢出的人。我不知道如何投票赞成评论中的答案。谢谢你的回答。我真想投票赞成你的答案。但我只有14个名声。