I've retrieved rows as objects from a class in Parse and store them in an array to use it later in a table view. I could successfully do that for all columns in the class except for two columns which are createdAt and updatedAt those two are created automatically by Parse every time we add a new row.
When I print the array, I see all the columns except createdAt and updatedAt.
This is the function I created to retrieve the data and store it in the array of objects and it works fine except for createdAt and updatedAt.
Thanks for help in advanced!
Actually I've found the answer which is that the columns objectId, createdAt and updatedAt that are created automatically by Parse are properties and we have to call them alone and they can't be retrieved with the whole object.
I called the object "article" so I can get the createdAt like this
let theDate = article.createdAt
The type here will be Date? and if you want to embed it within the table view you have to convert to String.
Related
I have a List of objects, which I need to sort by a date property. I'm using that list to display the items in a UITableView
My problem is that, sorting a List in Realm returns a Results<myItem> instead of a List<myItem> object.
What is the proper way to sort a List in Realm without converting it into a Results object?
Workaround can be:
add extra field like timestamp of your date property (in millis), everytime you insert a record. (not required if you are sorting data based on data field)
sort query data = data!.sorted(byKeyPath: "date", ascending: false) for more options
Realm query will return RLMResult only.for unmanaged object
I have the following Entity model (name and data type) in Core Data:
Item - String
Timestamp - Date
Value - Double
Is there any way to fetch the equivalent of "select date(timestamp) as date_value, sum(value) from Entity group by date_value, value"?
Googling on groupings doesn't explain how to do this with the Date type very clearly. I tried a workaround by adding a new column called date_string where it's a formatted String version of the Timestamp column, like '2018-03-19', but it doesn't seem very elegant and doesn't really work.
You don’t do this while fetching when using Core Data but rather fetch all relevant objects and then do the grouping and summation in your code.
I would use a dictionary with dictionaries for this, date (as string) as key and double as value for the inner dictionary and the item property as key and the inner dictionary as value for the outer dictionary. Or alternatively create a summation structure and use that in a single dictionary.
I have an Entity in coredata that I fetch. I pass this Entity around to other View Controllers, one of those ViewControllers has a UITableView that I would like to display based on the Date attribute (part of the Entity I am passing around) from newest to oldest. I'm just not sure how to re-organize that data so that the date Attributes are in chronological order after the Entity has already been fetched.
Update
This is what I tried to add
CurrentStatment is my Entity, and I access another set of Entities through it called History. History has an attribute called date, which is the value I'm trying to compare.
// sort date array
historyArray = currentStatement?.history?.array as! [History]
historyArray.sorted(by:{$0.date!.compare($1.date as! Date) == .orderedAscending})
But I am getting a warning: Result to call to 'sorted(by) is unused
You can sort an array using myArray.sorted(by: ...)
So, in your case, to sort the dates newest-to-oldest, use: let sortedEntities = myEntityArray.sorted(by: {$0.Date.compare($1.Date) == .orderAscending})
More on the subject: https://developer.apple.com/reference/swift/sequence/2296242-sorted
I have a Parse class called Book. Inside it is a column pageNumber.
I want to query the most recent objects for each page number. There can be more than one object with the same pageNumber which is why I only want to query the most recent object for each value under pageNumber.
So, if there are six different objects with a value of (4) under pageNumber in the class Book how would I get just the most recently created object. Not just for pageNumber (4) but for all unique pageNumbers 1-50.
For a specific page number :
You should order the result by createdAt date, and set the limit of the query to 1 :
query.descending("createdAt");
query.limit(1);
For each page number, you can either iterate on every possible page number value, or retrieve everything and iterate other the results, selecting the most recent object for the same page number (using a hash table)
I have multiple objects with the same valued in the "name" Column.i want to get the latest two objects that have been created in parse.
For example
COlUMNNAME COLUMNNAME2 CREATEDAT
THIS IS A STRING 0 2015-05-25T08:16:03.672Z
THIS IS A STRING 1 2015-04-25T08:16:03.672Z
THIS IS A STRING 1 2015-03-25T08:16:03.672Z
The query should return the first two rows.Is there a way to do that in parse?
You can use the query constraints where you can order based on createdAt feature. Following that via using the query limit options you can set a number that you want Parse to return(such as query.limit(2)). Hope this helps.
Regards.