nsfetchrequest

UITableView not updating DataSource after change to NSFetchedResultsController

那年仲夏 提交于 2020-01-02 04:47:07
问题 I have an UITableView populated by a NSFetchedResultsController . The initial fetch works fine. I can add, remove, modify, etc with zero problems.. But I want to add user-defined sorting to the table. I am doing this by changing the NSFetchedResultsController to use a different sortDescriptor set, and a different sectionNameKeyPath . Here is the code where I change the fetch: -(void)changeFetchData { fetchedResultsController = nil; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

Take action when two separate NSFetchRequests have both completed

守給你的承諾、 提交于 2020-01-01 07:01:12
问题 I'm using a remote database with Core Data and when I execute the following fetch requests, depending on the internet connection, it can take some time. I'd like to monitor these two requests and, when they are complete -- whether successful or failed -- I'd like to trigger another method. FetchRequest 1: [self.managedObjectContext executeFetchRequest:fetchRequest1 onSuccess:^(NSArray *results) { //Succcess [self.refreshControl endRefreshing]; } onFailure:^(NSError *error) { [self

“Whole word” search in a NSString through NSPredicate

99封情书 提交于 2020-01-01 01:13:16
问题 I would like to search if in the attribute description (an NSString instance) there is a given word. I tried with this predicate: [NSPredicate predicateWithFormat:@"description CONTAINS[cd] %@", theWord]; It works, but it finds also sub-words . For example, given theWord : Car it will mach also this description : A Christmas Carol Instead, I would like that my predicate will match only a , or christmas , or carol . (I'm using Core Data and NSFetchRequest.) 回答1: Something like this? NSString

How do I make a fetch request using NSManagedObject's new fetchRequest function?

。_饼干妹妹 提交于 2019-12-31 20:07:45
问题 In iOS 10 the CoreData team added a new "fetchRequest" method to NSManagedObject. It looks like this: public class func fetchRequest() -> NSFetchRequest<NSFetchRequestResult> Which, from what I understand, allows us to replace this: let request = NSFetchRequest<MyEntity>(entityName: "MyEntity") with this: let request = MyEntity.fetchRequest() However, when I try to make a simple request like this: let request = MyEntity.fetchRequest() do { results = try request.execute() } catch let error {

Swift 3. NSFetchRequest propertiesToFetch

久未见 提交于 2019-12-30 11:16:08
问题 In Swift 3 when we use NSFetchRequest , we have to specify NSFetchRequestResult . But how to get an array of properties values? If I use something like this let fetchRequest = NSFetchRequest<MyClass>(entityName: "MyClass") fetchRequest.propertiesToFetch = ["myAttributeName"] an exception fires when I try to execute fetch request. error: -executeRequest: encountered exception = The database appears corrupt. If I remove a line with propertiesToFetch I don't get any errors, but I get an array of

Form NSPredicate from string that contains id's

余生长醉 提交于 2019-12-29 01:23:11
问题 I have this problem where I can't think of how to write this predicate. I have an Entity called Contact, it has a string property "pages", let's say contact.pages = @"1,5,11,15,17"; There is a lot of contacts in my database, and I want to fetch only these contacts that contains a certain id. So let's say I want to fetch only these contacts, which pages contains id @"1". I can think of something like this, NSPredicate* predicate = [NSPredicate predicateWithFormat:@"self.pages CONTAINS %@",

UITableView not displaying the correct number of sections and rows from the fetch request array result

人盡茶涼 提交于 2019-12-25 08:36:42
问题 I think my problem spans over multiple VC. In the table VC I perform a fetch request that returns an array of Floor objects. This entity has 2 attributes (floor number and number of rooms in floors). If I assign 2 floors (0 and 1) it works and prints them. The next VC contains a picker that displays the number of floors and a text box that is used to assign the number of rooms per floor. There must be a problem with this function because it gets called only if the first item of the picker is

fetch coredata relationship

喜你入骨 提交于 2019-12-25 01:43:26
问题 I would like to know how to fetch the items from my coredata relation ship. I guess it should be a dictionary or arrays or something that gets returned so that you can have your one to many thing. I am quite lost at this I know how to write/read single objects but this relationship stuff is abit confusing. I think I have sucsessfully written a relationship to coredata however now I would like to be able to read it to see if I have it right.. I have started writing the method for this but have

Core Data: Sort by Relationship's Attribute

为君一笑 提交于 2019-12-24 17:53:38
问题 I'm building an open-source clone of iPhone's native Messages app called AcaniChat on GitHub. I have a Conversation entity and a Message entity with a sentDate attribute. Each Conversation can have many Message s. How do I fetch Conversation s sorted by the sentDate of it's oldest Message ? 回答1: The best way I can think of doing this is by adding an attribute to the Conversation entity called lastMessageSentDate and, every time a Message comes in and gets added to a Conversation , setting

Accessing data in retrieved Managed Object with Core Data

穿精又带淫゛_ 提交于 2019-12-24 15:33:38
问题 I'm trying to access a data in the retrieved Managed Object. Xcode giving me error "Cannot subscript a value type "[AnyObject]?" with an index of type 'int'". Doesn anybody know what I should do to? Thank you This is my method which saves data and which is called from my viewDidLoad method: // save data func saveData (jmeno:String, adresa:String, telefon:String) { // delegate let delegate = UIApplication.sharedApplication().delegate as! AppDelegate // managed object context let