[英]Variable used within its own initial value
我想在UIImageView類型的數組內附加值。 需要添加的值取決於其他值。 這是我對數組的聲明:
var images: [UIImage] = [UIImage(named: "")!]
這是我的代碼:
let cardIndex = playableCards.index (where: { $0.currentTitle! == button.currentTitle! })
{
images[cardIndex] = [UIImage(named: "")!]
}
不,我想知道我在做什么錯。 我只想向cardIndex告訴我的索引添加值。 我也嘗試過添加以下內容:
while howManyCardsNeedsToBeUnlocked != 0{
images.append(UIImage(named: "")!)
howManyCardsNeedsToBeUnlocked - 1
}
這樣圖像始終具有索引。 謝謝您的幫助。
playableCards.index (where: { $0.currentTitle! == button.currentTitle! })
返回一個可選值,因此您需要先解開該值,然后才能使用它。 我認為編譯器給您錯誤的錯誤,應該告訴您解開值。 if let
我將其解開。
if let cardIndex = playableCards.index(where: { $0.currentTitle! == button.currentTitle! }) {
images[cardIndex] = UIImage(named: "")!
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.