Efficient way to obtain section index from NSFetchedResultsController grouped by date - ios

I am building a calendar for iOS based on UICollectionView (GitHub link), based on the one that you can find at this repo. The underlying reasoning behind it is well described on this Objc.io issue.
To put it short, the process involves creating a NSFetchedResultsController that queries the events grouping them by day and displaying them in a (customized) UICollectionView afterwards.
The original calendar has the following inconvenient: since it is based on the sections contained in NSFetchedResultsController, it simply puts the date as the section header but ignores the days where there are no events happening. In this scenario, the index of the section contained in the NSFetchedResultsController matches 1:1 the sections of the calendar.
I made modifications in order to base the calculation of section headers based on calendar days, but now there is not a 1:1 correspondence anymore between the sections in the NSFetchedResultsController and the sections of the UICollectionView. Remember that the sections are based on the days.
This is the way I am currently doing it now, when I need to get the index of the section for a certain day:
- (NSInteger)sectionForDate:(NSDate*)day
{
return [[self.fetchedResultsController.sections valueForKey:#"name"] indexOfObject:[NSString stringWithFormat:#"%#", day]];
}
Here's the question: is there a more efficient way to get the section index out of the NSFetchedResultsController ?
If you think I should have used a different approach, please let me know.

There is absolutely no problem in having different sections from the FRC and in your datasource methods. The logic becomes a little bit more complicated, but it is a not so unusual pattern. There should be no drawbacks in efficiency.
I recently wrote an app where you can even switch between showing all days or only those with events, similar to Apple's calendar where in the list view the "empty" days are skipped as well.

Related

Creating Dynamic Sheet Cell Reference List for pulling numbers to SUM

I've been working on building a data analysis sheet, which is quite verbose at the moment and a bit more complicated than it should be as I've been trying to figure this out. Please note, I work doing student data in a school.
Basically, I have two sets of input data:
Data imported from a CSV file that includes test data and codes for Common Core Standards and the questions tied to those standards as a whole class summary
Data imported from a CSV file that includes individual scores by question
I am looking to construct 2 views:
A view that collates and displays data of individual standards per student that includes a dropdown to change the standard allowing a teacher to see class performance by standard in a broad view. The drop-down is populated dynamically from the input data (so staff could eventually dump data and go directly to reports)
A view that collates and displays data of individual students broken down by performance on each standard allowing a teachers to see the broader spectrum for each student. The student drop-down is populated from Source list 2.
I have been able to build the first view, but am struggling with the second. I've been able to separate the question codes and develop strings of cell references to the scoring data, including a dynamic reference to the row the selected student's score data appears on in the second source set from above.
I tried to pass through an indirect() formula into a sum() so as to process for a mean evaluation, and have encountered errors. I think SUM() doesn't process comma-separated cell reference lists from Indirect() [or in general] or there is something that I am missing to help parse it. Here is the formula I have tried:
=Sum(vlookup(D7,CCCodeManip!$A:$C,3,false))
CCCodeManip!C:C includes the created text (based on the dynamic standards and question codes, etc), here's an example of what would be found there:
'M-ADI'!M17, 'M-ADI'!N17, 'M-ADI'!O17, 'M-ADI'!P17, 'M-ADI'!Q17, 'M-ADI'!R17, 'M-ADI'!J17
I need these to be dynamic so that teachers can input different sets of standards, question, and student data and the sheet automatically collates and reports it in uniform ways (with an upward bound of 20 standards as I currently have it built)
Here is a link to the sheet I built, with names and ID anonymized. There's a CRAP TON of sub-tabs, and that's really just being able to split apart and re-combine data neatly without things error-ing out due to data overlapping, aside from a few different attempts and different approaches to parse the cell reference strings.
The first two tabs are the current status of the data views. I plan to hide a bunch of the functional stuff that is there to help pull data accurately.
The 3rd and 4th tab are the source data sets. 5th is a modified version of source data that allows me to reference things better, and I've tried to arrange the sheets most relevant towards the front of the set.
https://docs.google.com/spreadsheets/d/1fR_2n60lenxkvjZSzp2VDGyTUO6l-3wzwaV4P-IQ_5Y/edit?usp=sharing
Some have a different approach? I am aware that I might be as far as I cn go with this and perhaps should consider scripts - my coding experience is a bit out of date and my strength is more with the formulas, but I can dig into things with some direction, if anyone can help.
Ok so I noticed something.
It seems the failure is in the indirect reference:
=indirect(CCCodeManip!C3)
The string I am trying to parse via indirect is going to be generated into something like this, dynamic from reference to other data:
'M-ADI'!M17, 'M-ADI'!N17, 'M-ADI'!O17, 'M-ADI'!P17, 'M-ADI'!Q17, 'M-ADI'!R17, 'M-ADI'!J17
The indirect returns the error that the above string is not a cell reference with the #REF code.
Can someone give me a clue as to what is causing this? I am going to dig into the docs on Indirect() from google and will post anything that I find.
Perhaps it is that indirect() can't handle lists, but only specific references and arrays, which may require me a to build a sheet to do the SUM formula on for each question set (?)
So I think I figured it out, but i Ended up parsing the data differently, basically doing the sum based on individual cell references and a separate sum formula, bypassing the need to do it all at once, it jsut makes my sheets a lot dirtier! I am eventually going to see if code could do it better if I need to, but this is closed for now.
Basically, I did individual cell references to recall scores in a row, then used a separate SUM formula, and created references / structures to be able to pull those sum() results. Achieves the same end, but with extra crap on the sheet.

Parse.com how to separate objects based on createdAt day?

I've been looking to query for all of the "posts" a user has made, which I've done, and then separate them into sections in a UICollectionViewCell based on their createdAt day. So that my collection view headers will have the day and the under there will be to posts made that day. Perhaps I'm overthinking this too much? Thanks for any help!
This answer provides a way to get the start and end dates for the current day.
You'll then have to figure out how to sort the objects, but I'll leave that up to you.
Separating a lot of objects out into sections with NSDate comparisions may or may not affect your app's performance, so you'll have to be wary of that, but don't worry about it if you don't notice anything.

Set each sections of tableview with different query data from Parse

What I am looking to do is have 2 sections in my tableview which I can do by specifying 2. From there I am stuck. I am performing 2 queries from Parse to gather the details I need. 1 query gather extremely urgent data and the second is data about less important events. Each query has its own array so I am thinking it should be pretty easy to accomplish.
How do I set the first section to the urgent array (self.urgent) and the second to the less important events array (self.event)? I know how to configure cells for a single section with an array but have never had to configure 2 section with different results.
Thank you in advance.

Data sorting and update of UIcollectionViewCells. Is this a lost cause?

I have core data entries displayed in a collectionView, sorted from 1 2 3 ... n. New batches of entries are added as the user flips through the first n. Data is built from a JSON response obtained from a web server.
Because the first entry of the fetch request is associated to cell 0 - via the datasource delegate -, it's not possible to add a new batch at the bottom of the collection view. If it's added from cell 0, old cell contents are replaced by new ones, or in short the whole page seems to be replaced by new stuff, and the data the user was looking at is offset by the number of new entry. If the batch is large, it's simply buried. Furthermore, if the update is done from cell 0, all entries are made visible, which takes time and memory.
There are several options that I considered:
1) data-redorder, meaning instead of getting the fetch result as 1 2 3 4 ... n, I need the opposite, n ... 3 2 1 (nothing to do with a fetch using reverse order sorting) straight from the fetch request. I'm not sure it's possible? is there a CD gotcha allowing to re-order the fetch result before it is presented to the UICollectionViewDataSource delegate ?
2)Change the Index path/viewCell association in "collectionView cellForItemAtIndexPath:", Use (numberOfItemsInSection - IndexPath.Item). It creates several edges cases, as entries can be removed/updated in the view (hence numberOfItemsInSection changes). So I'd rather avoid it if I can...
3) adding new data from cell 0, ruled out for the reason I explained. There may be a solution: has anyone achieved a satisfactory result by setting a view offset? For example, if 20 new entries are added, then the content of cell 0 is moved to cell 20. So, we just need to tell the view controller to display from cell 20 onwards. Any image flipping or side effects I might expect?
4) download a big chunk of the data, and simply using the built-in core data faulting mechanism. But that's below optimal, because I'm not sure exactly how much I should download - user dependent - and the initial request (JSON+Core Data) might take too long. That's why lazy fetching is here for anyway.
Any advice someone facing the same problem could share ?
Thanks !

UItableView sorted by date in sections (and persistence)

I have several HistoryItems which contain an ID, Title and Date.
The Date is an NSDate of the exact time it was added to the history down to the second.
At the moment I just have an NSArray of these objects, the latest HistoryItem added to the end of the NSArray.
How do I make these items display in a UItableView cell in order of date, the latest being in the top, but also each day must have it's own section.
I also need these HistoryItems to be persistent between exit and loading of apps, so should I go with just saving the NSArray to a file, or using CoreData?
Using CoreData will probably be easier since you can use NSFetchedResultsController to manage the sections 'automatically'. Actually using a NSDate as a sectionKeyPath can be a bit problematic but as luck has it Apple has some sample code that you should be able to modify from having a section per month to a section per day.
Going with CoreData also gives you the sorting essentially for free.

Resources