Welcome, Guest
Username Password: Remember me

Filtering CoreData results
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Filtering CoreData results

Filtering CoreData results 1 year, 7 months ago #1

Hello,

How do I filter my CoreData results when using SCClassDefinition?

I have the following code:
 
SCClassDefinition *recentProductsDef =
[SCClassDefinition definitionWithEntityName:@"STIStoredProductEntity" withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"name", nil]];
 
SCPropertyDefinition *recentsPropertyDef = [recentProductsDef propertyDefinitionWithName:@"recents"];
recentsPropertyDef.attributes = [SCArrayOfObjectsAttributes attributesWithObjectClassDefinition:recentProductsDef
allowAddingItems:NO
allowDeletingItems:YES
allowMovingItems:NO];
 


Previously my STIStoredProductEntity would contain everything that I wanted to fetch, so it just fetched everything. But now I want to quality on an attribute of my model in order to filter the list.

How does one do that? definitionWithEntityName doesn't take an NSPredicate or anything like that.

Thanks,

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: Filtering CoreData results 1 year, 7 months ago #2

Hey Brendan,

We are currently working on a generic filtering system using NSFetchRequest. For the time being, please feel free to use a great solution developed by Gary Edge based on developing a category for SCArrayOfObjectsSection: www.sensiblecocoa.com/forum/sensible-tab...ew-sections.html#723

I will keep you posted when our system is ready. Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Filtering CoreData results 1 year, 7 months ago #3

Alright, I'll give that a try. Thanks.

Will that automatically handle updates that occur to the managed object context? That is, if I insert a new object into the database on a different screen, then come back to my list view, will the list view be updated automatically with the new object? That is, will the fetch from the database be re-issued when I do a [tableView reloadData] ?

Thanks,

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: Filtering CoreData results 1 year, 7 months ago #4

Ok, I got the section category working, but I had to make it work with SCArrayOfObjectsSection instead of SCTableViewSection. One of the methods the category was calling wasn't available on SCTableViewSection.

Anyway, how do I get the data to refresh? I've tried [tableView reloadData] and [tableModel reloadBoundValues] but none seem to re-trigger the CoreData fetch.

Do I have to manually remove my section from the tableModel and then re-execute my code to generate the SCArrayOfObjectsSection? Or is there a more preferred way to refresh the data?

The reason I ask this is I am maintaining a list of recently scanned product bar codes. One tab of my application contains the scanner. When you scan a product, it displays the product details after it looks it up on our servers. It then saves the product to my CoreData database. Then, another tab displays a list of recently scanned products. The problem is, when I switch to the Recents tab, the newly scanned products don't show up.

I've added this code to viewDidAppear:
 
-(void) viewDidAppear:(BOOL)animated {
[self.tableModel reloadBoundValues];
[self.aTableView reloadData];
[super viewDidAppear:animated];
}
 


But that's not refreshing the list.

Thanks,

Brendan
  • tapforms
  • OFFLINE
  • Expert Boarder
  • Posts: 120
  • Karma: 4
Thanks!
Brendan
www.tapforms.com

Re: Filtering CoreData results 1 year, 7 months ago #5

Hi Brendan,

To change the items of an SCArrayOfObjectsSection after the table have been displayed, you need to do two things:

1- Set the "items" or "itemsSet" property to the new set of items you need displayed.
2- Call [tableView reloadData] or [tableView reloadSections:withRowAnimation:].

Also, we will most probably be adding a "refresh" method as part of our generic NSFetchRequest system I discussed earlier, so that should make things a lot easier.

Please tell me if you need any more help.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Filtering CoreData results 1 year, 5 months ago #6

Hi Tarek,did you ever end up adding the 'refresh' method you mentioned above. I sometimes need to update the data model as a result of an import and would like to just tell my SCArrayOfObjects section to go to back to the data model and get any new objects.
  • oldbeamer
  • OFFLINE
  • Junior Boarder
  • Posts: 37
  • Karma: 0
  • Page:
  • 1
  • 2
Time to create page: 1.01 seconds