I could instantiate class from string in ObjC.For example,I have defined new DBCell class through subclassing UITableViewCell,and I instantiate class from name with these codes:
DBCell *cell=[tableView dequeueReusableCellWithIdentifier:cellClassname];
if (cell==nil) {
Class cellClass=NSClassFromString(cellClassname);
cell=[cellClass alloc];
cell=[cell initWithStyle:cellStyle reuseIdentifier:cellClassname];
}
Now I need migrate codes to Swift,I have redefined DBCell class in Swift:
class DBCell: UITableViewCell {
var label:String?
var key:String?
var managedObject:NSManagedObject?
var delegate:AnyObject?
convenience override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
self.init(style: style, reuseIdentifier: reuseIdentifier)
self.textLabel.font=UIFont.preferredFontForTextStyle(UIFontTextStyleCaption1)
self.backgroundColor=UIColor.blackColor()
self.textLabel.backgroundColor=UIColor.blackColor()
}
}
But how can I instantiate class and invoke the appropriate init function?