gpt4 book ai didi

ios - (Int) -> $T4 与 NSMutableArray 不同

转载 作者:行者123 更新时间:2023-11-28 13:14:48 25 4
gpt4 key购买 nike

我的问题已作为标题提出。让我描述一下。

  1. 我声明了一个名为 items 的 NSMutableArray 实例,并将 20 分配给它的 capacity

    var items = NSMutableArray()
    items = NSMutableArray(容量: 20)

  2. 我在我的应用程序中使用了 UICollectionView,但 UICollectionView 的委托(delegate)方法有错误。

    func collectionView(collectionView: UICollectionView!, moveItemAtIndexPath fromIndexPath: NSIndexPath!, toIndexPath: NSIndexPath!) {
    var 东西:NSString = items(fromIndexPath.item)
    self.items.removeObjectAtIndex(fromIndexPath.item)
    self.items.insertObject(事物,atIndex:toIndexPath.item)
    }

    方法的第三行,var thing: NSString = items(fromIndexPath.item) ,返回一个错误--- (Int) -> $T4 is not identical to NSMutableArray

    请告诉我如何解决。

    非常感谢您的宝贵时间和指导。

    伊桑·乔

最佳答案

我建议使用强类型的原生 Swift 字符串数组:

var items:[String] = []

此外,从数组中检索时需要使用方括号:

let thing = items[fromIndexPath.item]

关于ios - (Int) -> $T4 与 NSMutableArray 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29446063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com