gpt4 book ai didi

swift - 单步执行 Plist 并编写

转载 作者:行者123 更新时间:2023-11-30 12:35:27 24 4
gpt4 key购买 nike

我创建了一个供个人使用的应用程序,用于将数据从 BundlePath 中的模板写入两个 Plist 文件。在 Swift 3 之前一直工作得很好,我不确定是否将模板的索引作为键传递。

for index in 0 ..< number {


var diction = (resultQDictionary?.object(forKey: "Questions"))

print("diction = \(diction)")

//PROBLEM HERE!! - cannot call value of non function type 'Any?!' for dictionaryQItem and dictionaryAItem

var dictionaryQItem = (resultQDictionary?.object(forKey: "Questions") as AnyObject).object(index)
var dictionaryAItem = (resultADictionary?.object(forKey: "Answers") as AnyObject).object(index)

print("dQitem = \(dictionaryQItem)")

//print("this is DI for question = \(dictionaryItem?.objectForKey("Question"))")
//print(dictionaryItem?.objectForKey("Title"))



var cAns = inputSheetObjectArrayKey[index] //c
var quest = questionArray[index]
var title = titleArray[index]
var block = pickerBlock // blockArray[index]

var answerA = answerAArray[index]
var answerB = answerBArray[index]
var answerC = answerCArray[index]

//print("quest = \(quest)")

let trimmedcAns = (cAns as AnyObject).trimmingCharacters(in: CharacterSet.whitespaces)
let trimmedQuest = quest.trimmingCharacters(in: CharacterSet.whitespaces)
let trimmedTitle = title.trimmingCharacters(in: CharacterSet.whitespaces)
//let trimmedBlock = block.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
let trimmedAnswerA = answerA.trimmingCharacters(in: CharacterSet.whitespaces)
let trimmedAnswerB = answerB.trimmingCharacters(in: CharacterSet.whitespaces)
let trimmedAnswerC = answerC.trimmingCharacters(in: CharacterSet.whitespaces)



dictionaryQItem.setValue(trimmedcAns, forKey: "CorrectAnswer")
dictionaryQItem.setValue(trimmedQuest, forKey: "Question")
dictionaryQItem.setValue(trimmedTitle, forKey: "Title")
dictionaryQItem.setValue(pickerBlock, forKey: "Block")



dictionaryAItem.setValue(trimmedAnswerA, forKey: "A")
dictionaryAItem.setValue(trimmedAnswerB, forKey: "B")
dictionaryAItem.setValue(trimmedAnswerC, forKey: "C")
dictionaryAItem.setValue(trimmedTitle, forKey: "Title")
dictionaryAItem.setValue(" ", forKey: "FEEDBACK")


}

resultQDictionary?.write(toFile: docsQPath, atomically: false)
resultADictionary?.write(toFile: docsAPath, atomically: false)


}

无法调用非函数类型“Any?!”的值对于dictionaryQItem和dictionaryAItem - 在Swift 2.3中工作得很好,但我不确定如何传递索引。任何帮助表示赞赏!

最佳答案

我将 DictionaryAItem 和 DictionaryQItem 定义为类对象,并使用它们来管理问题和答案数据,特别是当您似乎具有明确定义的结构时。

关于swift - 单步执行 Plist 并编写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42932068/

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