我创建了一个供个人使用的应用程序,用于将数据从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)
}
无法调用非功能类型的值&#39;任何?!&#39;对于dictionaryQItem和dictionaryAItem - 在Swift 2.3中工作得很好,但我不确定如何传入索引。任何帮助表示赞赏!
答案 0 :(得分:0)
我将DictionaryAItem和DictionaryQItem定义为类对象,并使用它们来管理问题和答案数据,尤其是当你似乎有明确定义的结构时。