Date wise sectioning of a UITableView - iphone

Suppose I have a UITableViewController with an array "history" as data source. The array consists of an undefined number of NSDictionaries. Each dictionary contains the following keys: term (NSString), date (NSDate) and id (NSNumber).
I would like to map the contents of the history array according to the date values each dictionary has, i.e. I need to dynamically create sections, named and sorted according to the date values of each dictionary (the iPhone app wikipanion does this in its history view). Is there a best practice to do this? Otherwise I would just read out each date object, sort them into another dictionary, etc...

Best practice is to 'group by YYYY-MM-DD' and then 'sort by YYYY-MM-DD HH:MM:SS'. So this involves some simple grouping of your dictionaries into arrays. Now that you have an array of arrays you can sort those simply by date.

Related

How to sort firestore document id date wise firebase flutter

I am importing csv data to firestore by parsing it. The csv is making documents randomly without following the date's chronological order e.g 2019's data first and 2022 or latest data at last. I want to show the data chronological wise on the app side or even if possible on the javascript side of firebase while parsing I'm ready to make changes.
Format is dd-mm-yyyy I've tried orderBy but it didn't worked.
Note that there's Date field as well in my every document and I can't use Timestamp cause data is coming from csv.
I'm attaching image of my app and firestore document id and collection to get an better idea of what I want to achieve.
Document IDs are strings, so they use lexicographical sort order. If you want them to also be sorted chronologically, you should use a date format that fits those needs. For example ISO-8601: 2022-09-15. In this format, ordering by document ID will put the documents in the order of the date.

Flutter project Firestore data sorting

I have some data on my project firestore. It seems like this:
I am trying to sort this data by SKU. As you can see it is in a list. How can I give its field path to orderBy() method?
There is no way to sort the document you've shown on a SKU value, since that value exists in an array field and there could be multiple values.
If you want to sort on a specific SKU value, add a top-level field (e.g. skuForOrdering) to the document and sort on that with orderBy('skuForOrdering').

MongoDB: Sort if value is present in array or not

question: I have a document where a field picked_by_ids is an array of all user ids. Now I have to sort this table such that if provided id is there in picked_by_ids then it should come at top and all other records should list after that.
Note: We may have a large table and need to add indexing for this. Also need to add pagination.
Thanks.

Searching for subrow in an array

I have a problem with swift. I want to search an array of strings consists of 3 different elements filling this array in certain manner. Next i want to search the array for a subset of 3 particular strings next to each other and return their indexes. Is that a special array method for this?
Copied from comment:
Assumed i have an Int array like [1,2,1,3,2]. I want to search it for a subarray [1,2,1] and return indexes of those elements. Should i use findwithPredicate method?
I would just iterate the Array checking for matches.
Check the items in the array in sequence comparing the current item with the first item of the subarray. If it does not match move on. If it does start comparing the rest of the subarray, if it fails go bad to scanning the array.

Arrange NSDictionary unique value in iphone

Hi i am getting response form Json like this
{"items":[{"f":"djay","m":"hi ajay","d":"2012-9-22","id":"16"},{"f":"djay","m":"hi","d":"2012-9-22","id":"25"},{"f":"Chithri","m":"hi","d":"2012-9-23","id":"26"},{"f":"ChithriAtchibabu","m":"gig","d":"2012-9-23","id":"27"}]}
i want arrange my array like this
[{"time":"2012-9-22","data":[{"m":"hiajay"},{"m":hi}]},{"time":"2012-9-23","data":[{"m":"hi"},{"m":gig}]}]
can any one please guide me how could i arrange my array like this
An NSDictionary is an unsorted collection.
To sort the data in it makes no sense.
What you are doing in your post is completely rebuilding an array of dictionaries from another dictionary.
Also, a dictionary can't have duplicate keys.
To do this you'd have to go through the array "items" in your first dictionary and then create a new dictionary for each new date and then inside there put an array with the items in it. Or something...