How can I get the data quantity and date data from the parsing and put it in the UILabel?
I currently want to get createdAt and price from the parsing database and the data types for both are Number and NSDate . >. After I have extracted it, I want to go to the UILabel that matches the date and price . The problem right now is that whenever I tried to run the simulator, both UILabel data is not displayed while the row data type is displayed.
My current code
if let createdAt = object?["createdAt"] as? String {
cell.date.text = createdAt
}
if let priceTitle = object?["price"] as? String {
cell.price.text = priceTitle
}
+3
source to share
2 answers
For date use NSDateFormatter.stringFromDate method so your code is:
if let createdAt = object?["createdAt"] as? NSDate {
let dateFormatter = NSDateFormatter()
var theDateFormat = NSDateFormatterStyle.ShortStyle
dateFormatter.dateStyle = theDateFormat
cell.date.text = dateFormatter.stringFromDate(createdAt)
}
0
source to share
createdAt
- special meaning in Parse. This is a property PFObject
and you access it with dot notation. So this is how you should proceed:
if let object = object as? PFObject {
let date = object.createdAt
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "HH:mm MMMM dd, yyyy"
let dateStr = dateFormatter.stringFromDate(date!)
cell.date.text = dateStr
}
0
source to share