XMPPFramework Swift fetch objects always null -
hi have problem xmppframework using swift, 0 element when fetch objects
func fetchedresultscontroller() -> nsfetchedresultscontroller? { if fetchedresultscontrollervar == nil { let moc = managedobjectcontext_roster() 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 { try fetchedresultscontrollervar!.performfetch() } catch let error nserror { print("error: \(error.localizeddescription)") abort() } // if fetchedresultscontrollervar?.performfetch() == nil { //handle fetch error //} } return fetchedresultscontrollervar! }
i have activate in setup using code
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)
but when print in delegate functoin fetchedresultcontrollervar.fetchedobjects return 0,but jidlist can rosterlists.
func xmpprosterdidendpopulating(sender: xmpproster?){ var jidlist = xmpprosterstorage!.jidsforxmppstream(xmppstreams) fetchedresultscontrollervar!.fetchedobjects print("list=\(jidlist)") }
did miss something? must init xmppusercoredatastorageobject in class? thanks
you have make sure connected xmpp
before fetching roster
, if use xmppcoredata
.
i made swift wrapper
around xmppframework
, simplify development of basic chat app, , show how fetch roster
.
you can check out here.
Comments
Post a Comment