嗨,我使用SWIFT有xmppframework問題,獲取對象XMPPFramework斯威夫特獲取對象總是空
func fetchedResultsController() -> NSFetchedResultsController? {
if fetchedResultsControllerVar == nil {
let moc = managedObjectContext_roster() as NSManagedObjectContext?
let entity = NSEntityDescription.entityForName("XMPPUserCoreDataStorageObject", inManagedObjectContext: moc!)
let sd1 = NSSortDescriptor(key: "sectionNum", ascending: true)
let sd2 = NSSortDescriptor(key: "displayName", ascending: true)
let sortDescriptors = [sd1, sd2]
let fetchRequest = NSFetchRequest()
fetchRequest.entity = entity
fetchRequest.sortDescriptors = sortDescriptors
fetchRequest.fetchBatchSize = 10
fetchedResultsControllerVar = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: moc!, sectionNameKeyPath: "sectionNum", cacheName: nil)
fetchedResultsControllerVar?.delegate = self
do {
try fetchedResultsControllerVar!.performFetch()
} catch let error as NSError {
print("Error: \(error.localizedDescription)")
abort()
}
// if fetchedResultsControllerVar?.performFetch() == nil {
//Handle fetch error
//}
}
return fetchedResultsControllerVar!
}
我使用此代碼
xmppStreams = externalStream
xmppRosterStorage = XMPPRosterCoreDataStorage()
xmppRoster = XMPPRoster(rosterStorage: xmppRosterStorage)
xmppRoster!.autoFetchRoster = true;
xmppRoster!.autoAcceptKnownPresenceSubscriptionRequests = true;
xmppRoster!.addDelegate(self, delegateQueue: dispatch_get_main_queue())
xmppRoster!.activate(xmppStreams)
在我的設置激活時,我總是得到0元
但是,當我在委託functoin fetchedResultControllerVar.fetchedObjects打印它總是返回0,但對於jidList我可以得到我的名單。
func xmppRosterDidEndPopulating(sender: XMPPRoster?){
var jidList = xmppRosterStorage!.jidsForXMPPStream(xmppStreams)
fetchedResultsControllerVar!.fetchedObjects
print("List=\(jidList)")
}
我錯過了什麼嗎?我是否必須在我的類中初始化XMPPUserCoreDataStorageObject?謝謝
我正面臨同樣的錯誤。 http://stackoverflow.com/questions/28824377/in-coredata-entityforname-nil-is-not-a-legal-nsmanagedobjectcontext-parameter任何人都可以指導我..請。如何解決這個問題? –