Comments (9)
DO IT!
from datasource.
Done #29
from datasource.
Hey @3lvis , just curious what the reasoning was for making fetchedResultsController private. I have a need to subclass DATASource and it requires access to fetchedResultsController. I guess I can make a fork, but would rather not...
from datasource.
Hi @bonebox,
At the beginning it started with making convenience methods for handling common operations, using fetchedResultsController methods felt way too verbose:
=> self.dataSource.fetchedResultsController.fetchRequest.predicate
self.dataSource.predicate
=> self.dataSource.fetchedResultsController.fetchedObjects?.count ?? 0
self.dataSource.objectsCount
=> self.dataSource.fetchedResultsController.objectAtIndexPath(NSIndexPath(forRow: index, inSection: 0)) as? Song
self.dataSource.object(indexPath: NSIndexPath)
=> self.dataSource.fetchedResultsController.indexPathForObject(song)
self.dataSource.indexPath(object: NSManagedObject)
=> self.dataSource.fetchedResultsController.fetchedObjects!
self.dataSource.objects
=> if self.dataSource.fetchedResultsController.fetchedObjects?.count == 0 {
self.dataSource.isEmpty?
{
Then the issue with changing the fetchedResultsController's predicate started, updating the self.dataSource.fetchedResultsController.delegate
object isn't enough. You also have to do some clean up, and I had reports that updating the predicate was causing problems, so I went for just hiding the fetchedResultsController in order to push towards the use of the safer method.
DATASource/Source/DATASource.swift
Lines 79 to 94 in 535147d
from datasource.
Btw, what problem are you trying to solve? Maybe we can find another solution.
from datasource.
Hey @3lvis, thanks for the explanation--that's understandable. Perhaps a happy medium would be making it read-only? For example, public private(set) var fetchedResultsController: NSFetchedResultsController
would be the only change needed, and work for keeping it readable, but not writable.
As for the problem I'm trying to solve - I need to subclass DATASource
to override some of the UICollectionViewDataSource
methods to modify the return values, and it requires read access to fetchedResultsController
. The reason is the way my model is set up - I have a many-to-many relationship, and I need to fetch on one entity but display its relationship as the collection view items in order to section it properly. For example, say I have many-to-many Organization ←→ Person
, I need to fetch the Organization
entity and yet have each cell be a Person
in order to section by Organization
. Fetching by Person
doesn't work, since a Person
can belong to multiple Organization
s, I can't derive which specific Organization a certain Person
should belong to. This requires some manipulation of the datasource methods, similar to this. Hope that makes sense.
from datasource.
Actually after looking at it further, a few more of the properties/methods would also need to be made public/read-only in order to accomplish what I want to do. The configureCell
method would also have to be overridden, so would need to be public
. Also collectionConfigurationBlock
and tableConfigurationBlock
properties would need to be public private(set)
since they would need to be accessed in the overridden configureCell
method...
from datasource.
Anyway, don't worry about this. It's more of an edge-case that hardly anyone will likely need. I'll just create a fork and make my changes there. Thanks!
from datasource.
Hi Jeremy,
Thanks for taking the time of explaining. I understood what you're trying to achieve. I'm sure your users will appreciate the extra work that takes making something like this. I can imagine why it would be useful.
I hope it works out for you, if I can help in anything just let me know.
Have a nice weekend!
from datasource.
Related Issues (20)
- No Example to delete items in table-view HOT 2
- Predicate update for DATASource cause crash HOT 2
- Filtering DATASource HOT 2
- Sorting by distance HOT 6
- Pagination HOT 5
- Customizing change animations in Objective C HOT 3
- How to change predicate on fetchrequest? HOT 3
- NSRangeException exception in NSFetchedResultsChangeUpdate event of NSFetchedResultsController HOT 2
- UITableVIew swipe trailingSwipeActionsConfigurationForRowAt not working HOT 4
- sortDescriptors proposal HOT 4
- NSInternalInconsistencyException at controllerDidChangeContent (DATASource+NSFetchedResultsControllerDelegate.swift:137) HOT 5
- Updating core data object causes DATASource to delete from tableView HOT 5
- Invalid Update Crash HOT 1
- Unit test viewForSupplementaryElementOfKind with title HOT 1
- Multiple cell identifier support HOT 7
- TableViewCRUDAndReorder Demo HOT 2
- Demo on multiple cell identifier
- Add a way to disable calling configure cell in cellForItemAt HOT 1
- Assertion failure in -[UITableView _endCellAnimationsWithContext HOT 10
- DidSelectRowAtIndexPath HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datasource.