【发布时间】:2018-04-12 02:52:17
【问题描述】:
这里有一些 Parse-Server 相关的 swift 代码不起作用,可能只是因为一些明显的语法错误。
如果有人能指出问题,我将非常高兴和感激。
func getSentenceTranslations(_ sentences:[PFObject]) {
let query = PFQuery(className: "TranslationsList")
query.whereKey("sentence", containedIn: sentences)
query.addAscendingOrder("order")
query.findObjectsInBackground {
[weak self] (objects: [PFObject]?, error: Error?) in
if error != nil {
print("Error in \(#function)\n" + (error?.localizedDescription)!)
return
}
// The line below prints the expected number (> 0).
print("\(objects?.count ?? 99) translations found.")
for sentence in sentences {
for translation in objects! {
// The following does not work!!
if (translation.value(forKey: "sentence") as! PFObject) == sentence {
print("FTF: \(sentence.value(forKey: "sentence")!)") // MISSING!!
}
}
}
}
}
但事实是,如果我在正确的时刻停止调试器,我可以看到注释行上应该有一个命中 (MISSING!!)。以下是调试器显示的内容:
(lldb) p sentence.debugDescription
(String) $R31 = "<SentencesList: 0x1073j7450, objectId: krxX9WsZuxK, localId: (null)> {\n order = 3;\n owner = Ht8AbcR543;\n sentence = \"Hello big world of things.\";\n}"
(lldb) p translation.debugDescription
(String) $R32 = "<TranslationsList: 0x10739f0e0, objectId: FoBdjoPF1n, localId: (null)> {\n order = 0;\n owner = Ht8AbcR543;\n sentence = \"<SentencesList: 0x1073aa8c0, objectId: krxX9WsZuxK, localId: (null)>\";\n translation = \"Die Welt von immer!\";\n}"
(lldb)
我们可以看到值 krxX9WsZuxK 在句子 (objectId) 和翻译 (sentence field) 上都可以找到,所以我希望有这样一行:
FTF: .......
要打印,这不会发生。所以我怀疑这行有错误:
if (translation.value(forKey: "sentence") as! PFObject) == sentence {
我尝试了各种其他变体都失败了。
【问题讨论】:
标签: ios swift parse-server pfquery