Malorrr
Malorrr

Reputation: 263

Select creationDate from CloudKit record

I'm trying to fill a cell with title and subtitle. Title with the field and detail with the CreationDate from the record.

I am trying the following but I am getting a no member 'ObjectForKey'

var objects = CKRecord

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let reuseIdentifier = "Cell"
    var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as UITableViewCell?
    if (cell != nil) {
        cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
    }

    let object = objects[indexPath.row]
    cell!.textLabel!.text = object.objectForKey("Notes") as? String
    cell!.detailTextLabel?.text = object.creationDate.objectForKey("Notes") as? String
    return cell!
}

Upvotes: 0

Views: 318

Answers (1)

rmaddy
rmaddy

Reputation: 318774

The error is from this line:

cell!.detailTextLabel?.text = object.creationDate.objectForKey("Notes") as? String

For some reason you are trying to get the "Notes" key from the record's creation date (which is an NSDate.

Just get the creationDate as an NSDate. Then use an NSDateFormatter to format the date into a string you can assign to the detailTextLabel.text.

Upvotes: 2

Related Questions