相关疑难解决方法(0)

如何在Swift中找到列表项的索引?

我试图通过搜索列表找到项目索引.有谁知道怎么做?

我看到有item index,list但我想要像python的东西list.StartIndex.

arrays swift

419
推荐指数
16
解决办法
42万
查看次数

如何从Swift中的数组中删除元素

如何在Apple的新语言Swift中取消/删除数组中的元素?

这是一些代码:

let animals = ["cats", "dogs", "chimps", "moose"]
Run Code Online (Sandbox Code Playgroud)

如何animals[2]从阵列中删除元素?

arrays swift

207
推荐指数
14
解决办法
25万
查看次数

我如何实现Swift的Comparable协议?

如何在Swift中使用Comparable协议?在声明中它说我必须实现三个操作<,<=和> =.我把所有这些都放在课堂上,但它不起作用.我还需要拥有这三个吗?因为应该可以从一个推断出所有这些.

compare protocols swift

34
推荐指数
2
解决办法
1万
查看次数

如何在Swift中找到项目的索引?

有没有一种名为indexof或类似的方法?

var array = ["Jason", "Charles", "David"]

indexOf(array, "Jason") // Should return 0
Run Code Online (Sandbox Code Playgroud)

swift

33
推荐指数
3
解决办法
7万
查看次数

How to invoke Swift Array.indexOf?

Here's a snippet of code where I get a syntax error I don't understand:

  let deal:[Card] = self.cards
       for hand in hands {
           var data:[Int] = []
           for card:Card in hand.cards {
               let idx = deal.indexOf(card) 
               data.append(idx!)
           }
       }
Run Code Online (Sandbox Code Playgroud)

The error I get is "Cannot invoke 'indexOf' with an argument of type '(Card)'". I don't understand this at all. deal is an [Card]. What should I invoke deal.indexOf with if not a Card? The signature for CollectionType.indexOf in the docs …

arrays swift

0
推荐指数
1
解决办法
569
查看次数

标签 统计

swift ×5

arrays ×3

compare ×1

protocols ×1