HomeiOS Developmentios - Generic Class with Enum with related values

ios – Generic Class with Enum with related values


I am attempting to create a generic UITableViewCell that inherits from an enum with related values.
That is what I attempted:

Enum declaration:

enum Content material: Equatable  {
    case textual content(String)
    case picture(UIImage)
    case error(Error)
    case indicator
}

And UITableViewCell declaration:

class MessageTableViewCell<T: Content material>: UITableViewCell {
    var content material: T?
}

Nevertheless it fails with:

Sort 'T' constrained to non-protocol, non-class sort 'Content material'

I am attempting to arrange my cell with various kinds of “content material view,” relying on its content material. Do be aware: I am utilizing XIB for the interface of the cell, so subclassing is just not attainable (I feel). Any recommendation will probably be extremely appreciated!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments