ios - Core Data takes too much time -


i have around 200,000 4 letter words, want use in app. don't want use csv file in app. using core data now. loading these values core data @ starting of app first time. , retrieving these values after sometime.

so procedure time, more 20 seconds think. want access single word, want know whether word exists in core data or not, there other ways this, except looping through whole array.

simply, want check whether word exists in core data or not, want access word ints index, don't wanna loop through objects. there other way .? want in fraction of second.how supposed load 0.2 million words .? reading csv takes more 2 minutes, in app. suggestion importing array of string core data.?

this code using in project.

 // save coredata       func savename()     {          //1 getting appdelegate          let appdelegate = uiapplication.sharedapplication().delegate as! appdelegate          let managedcontext = appdelegate.managedobjectcontext!          //2 fetching entity description corresponding entityname          let entity =  nsentitydescription.entityforname("content", inmanagedobjectcontext: managedcontext)          let tempmanagedobject = nsmanagedobject(entity: entity!, insertintomanagedobjectcontext:managedcontext)          //3 setting values managedobject           input in self.fourletterwords         {             tempmanagedobject.setvalue(input, forkey: self.kmainattributename)         }          //4          var error: nserror?          if !managedcontext.save(&error)         {             println("could not save \(error), \(error?.userinfo)")         }     }      //mark: - showing values core data      func showoutput()     {         var myarray : array<string> = []          //1         let appdelegate = uiapplication.sharedapplication().delegate as! appdelegate          let managedcontext = appdelegate.managedobjectcontext!          //2         let fetchrequest = nsfetchrequest(entityname: "content")          //3         var error: nserror?          let fetchedresults =         managedcontext.executefetchrequest(fetchrequest,             error: &error) as! [nsmanagedobject]?          if let results = fetchedresults         {             inputobject in results             {                 if let value : string = inputobject.valueforkeypath(self.kmainattributename) as? string                 {                     myarray.append(value)                 }             }         }         else         {             println("could not fetch \(error), \(error!.userinfo)")         }     } 

the important method need skip looping this:-

1 .filteredarrayusingpredicate: 

to search use this:-

nspredicate *predicate = [nspredicate predicatewithformat:@"any self contains %@", search]; 

just go through apple doc, surely you.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -