Reputation: 126507
Why does the first line in the method below give me an EXC_BAD_INSTRUCTION
runtime error?
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cellIdentifier = NSStringFromClass(MessageCell)
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as MessageCell
// ...
}
Upvotes: 0
Views: 604
Reputation: 126507
Actually, turns out the first line is OK. It was the second line causing the crash. UITableView in Swift has the solution.
Upvotes: 0
Reputation: 1243
Swift does not have the introspection capabilities yet as Obj-C does.
class Cell: UITableViewCell {
}
let a = NSStringFromClass(NSString) // prints NSString
let b = NSStringFromClass(Cell) // prints _TtC11lldb_expr_04Cell
let c = NSStringFromClass(UITableViewCell) // prints UITableViewCell
Since the identifier gets modified you try to dequeue a non-existent cell which leads to the mentioned error.
See also Get a user-readable version of the class name in swift (in objc NSStringFromClass was fine)
Upvotes: 1