I tried to use a class which is created from NSClassFromString to perform a class method, but I failed.
In Objective-C, it's easy:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:[NSClassFromString(reuseIdentifier) cellStyle] reuseIdentifier:reuseIdentifier];
if (self) {
let sel = #selector(CTFeedbackTopicCellItem.cellStyle())
// Initialization code
}
return self;
}
And in Swift it's not easy:
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
if let reuseIdentifier2 = reuseIdentifier
{
if let class2 = NSClassFromString(reuseIdentifier2) as? NSObjectProtocol
{
let sel = #selector(CTFeedbackCellItem.cellStyle())
if let class3 = class2 as? CTFeedbackCellItem
{
super.init(style: class3.cellStyle, reuseIdentifier: reuseIdentifier2)
}
}
}
}
The error shown in my Swift code so far are:
1. Argument of '#selector' does not refer to an '@objc' method, property or initializer.
2. Stastic member 'cellType' cannnot be used on instance of type 'CTFeedbackCellItem'
cellType
than it is a clear case for a protocol :) Anyway, this whole initializer looks weird. If you are already initializing this class, can't you just take itscellType
? Can you link to the library you are converting? – Losiowaty