-2
私はSwiftと私は現時点でちょっと立ち往生しています... "for"(***
と記されています)の部分でエラーが発生し続けています。なぜそれが見えませんか?ここで(キー:X、値:X)は '(_、_、..........)'に変換できません。タプルの要素数は異なります
は、全体のコードです:
private func startPreload() {
if UserDefaults.standard.bool(forKey: ISPRELOADED) {
return
}
let loans = readPreload()
// *** Error happens here:
for (name, amount, note, created, due, done, image, contactInfo, contactTypeMail, chargeMode, chargeAmount) in loans {
let _ = LoanResources.insertLoan(withName: name, andAmount: amount, andNote: note, andCreated: created, andDue: due, andDone: done, andImage: image, andContactInfo: contactInfo, andContactTypeMail: contactTypeMail, andChargeMode: chargeMode, andChargeAmount: chargeAmount)
}
UserDefaults.standard.set(true, forKey: ISPRELOADED)
}
private func readPreload() -> [String: String] {
var preparedLoans = [String: String]()
let preloadFileUrl = Bundle.main.url(forResource: "preload", withExtension: "strings")
do {
guard let fileLoan = preloadFileUrl else {
return preparedLoans
}
let data = try Data(contentsOf: fileLoan)
let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as! NSDictionary
let loanArray = json["Loans"] as! NSArray
for loan in loanArray {
let loanDict = loan as! NSDictionary
let name = loanDict["name"] as! String
let amount = loanDict["amount"] as! String
let note = loanDict["note"] as! String
let created = loanDict["created"] as! String
let due = loanDict["due"] as! String
let done = loanDict["done"] as! String
let image = loanDict["image"] as! String
let contactInfo = loanDict["contactInfo"] as! String
let contactTypeMail = loanDict["contactTypeMail"] as! String
let chargeMode = loanDict["chargeMode"] as! String
let chargeAmount = loanDict["chargeAmount"] as! String
preparedLoans[name] = name
preparedLoans[amount] = amount
preparedLoans[note] = note
preparedLoans[created] = created
preparedLoans[due] = due
preparedLoans[done] = done
preparedLoans[image] = image
preparedLoans[contactInfo] = contactInfo
preparedLoans[contactTypeMail] = contactTypeMail
preparedLoans[chargeMode] = chargeMode
preparedLoans[chargeAmount] = chargeAmount
}
} catch {
print(error.localizedDescription)
}
return preparedLoans
}
たぶん私はさらにステップと借入金のうち、キーと値を取得する必要がありますか?