![](/img/trans.png)
[英]Argument type 'SecretSpec' does not conform to expected type 'Sequence'
[英]How to solve “Argument type 'CustomStruct' does not conform to expected type 'Sequence'”
我嘗試使用下面的代碼洗牌陣列由稱為簡單的自定義結構的Card
,我在得到一個錯誤cards.remove(at: randomIndex)
Error: Argument type 'Card' does not conform to expected type 'Sequence'
以下是代碼:
var cards = [Card]() // declare the array
var shuffledCards = [Card]()
for _ in cards.indices {
let randomIndex = Int(arc4random_uniform(UInt32(cards.count)))
shuffledCards += cards.remove(at: randomIndex) // error appears here
}
cards = shuffledCards
奇怪的是,與此相反,類似的設計適用於Array<String>
:
var emojiChoices = ["🦇", "😱", "🙀", "😈", "🎃", "👻", "🍭", "🍬", "🍎"]
let randomIndex = Int(arc4random_uniform(UInt32(emojiChoices.count)))
emoji[card.identifier] = emojiChoices.remove(at: randomIndex)
我應該添加Card
的定義嗎? 如果是這樣,我應該添加什么? 謝謝!
中的+=
運算符
shuffledCards += cards.remove(at: randomIndex)
期望將元素序列附加到shuffledCards
數組(例如另一個數組)上。 要附加單個元素,請使用
shuffledCards.append(cards.remove(at: randomIndex))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.