Reputation: 2711
I have data saved in a Realm that I am trying to display in a custom tableview cell. Here is the code.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> JobTableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("JobCell") as! JobTableViewCell
//var jobs: Results<Job>?
let jobs = realm.objects(Job) as String
cell.nameLabel?.text = jobs.name
cell.addressLabel?.text = jobs.address
cell.phoneLabel?.text = jobs.phone
cell.emailLabel?.text = jobs.email
return cell
}
I am getting the error "Value of type'Results<(Job)> (aka 'Results) has no member 'name'. This error repeats on all four label lines.
I have tried to cast the type to String which eliminates the errors on the label lines, but creates a new error "Cannot convert value of type '(Job)' ... to expected argument type 'T.Type'
I am new to this so please excuse me if my post is not done correctly.
Upvotes: 0
Views: 775
Reputation: 14409
The problem is on this line:
realm.objects(Job) as String
The you're trying to convert Results<Job>
to a string, which is not a compatible type.
You probably want to apply the values of the item in some Realm Results
at the index of indexPath.row
to your cell's UI components like this:
let job = realm.objects(Job)[indexPath.row]
cell.nameLabel?.text = job.name
cell.addressLabel?.text = job.address
cell.phoneLabel?.text = job.phone
cell.emailLabel?.text = job.email
Upvotes: 1