2014-09-22 63 views
0

正在設置NSPredicate重寫我的客觀存在的C代碼(IOS),以迅速而現在在迅速面臨Coredata NSPredicate一些問題,因爲有一些多對一的關係,反之亦然..我用下面的代碼,斯威夫特CoreData

let fetchRequest = NSFetchRequest(entityName: "TUMessage") 
    let sortSequence = NSSortDescriptor(key: "sequence", ascending: true) 
    let sortTime = NSSortDescriptor(key: "epoch_time", ascending: true) 
    var filterPredicate:NSPredicate = NSPredicate(format:"thread == [c] %@",contact.threads.anyObject()) 
     fetchRequest.predicate = filterPredicate 
    var sortDescriptor:NSArray = NSArray(objects: sortTime,sortSequence) 
    fetchRequest.sortDescriptors = sortDescriptor 
    fetchRequest.fetchBatchSize = 50 
    return fetchRequest 

其中"TUMessage"是我們需要從,"sequence"用於排序的取出結果取數據的表,"thread == [c] %@"是消息表的關係(多對一因爲每個接觸有多個線程),

contact.threads.anyObject()是我試圖去做的謂詞add.Unfortunately正在以下錯誤

type anyobject? does not confirm to protocol, CVarArgType 

任何幫助,將不勝感激..

謝謝

+0

我目前無法檢查,但我假設你已經打開可選的:'contact.threads.anyObject()!' – 2014-09-22 12:48:26

+0

不,它不起作用 – sam 2014-09-22 13:01:41

+0

如果thread是一個relatiti onship,爲什麼你使用[c]執行不區分大小寫的搜索? – 2014-09-22 13:18:03

回答

1

你需要把它和投解開特定類

contact.threads.anyObject()! as MYClass