2

This is my protocol:

protocol LiveTableViewCellProtocol: class { var data: LiveCellObjectProtocol! { get set } } 

This is my class:

class RepliesTableViewCell: UITableViewCell, LiveTableViewCellProtocol { var data: RepliesCellObject! //ERROR! does not conform to protocol. } 

RepliesCellObject is defined as:

public class RepliesCellObject: NSObject , LiveCellObjectProtocol{ //basic stuff here. } 

RepliesCellObject is a LiveCellObjectProtocol ... so why doesn't my table cell conform?

1
  • In my RepliesTableViewCell, I must define my data as RepliesCellObject. Commented Jul 11, 2016 at 22:19

4 Answers 4

3

It doesn't conform because in an object that conforms to LiveTableViewCellProtocol, you can set data to any LiveCellObjectProtocol, including one that isn't an NSObject. In RepliesTableViewCell, you can't do that. The data must be set to a LiveCellObjectProtocol that is also an NSObject.

Therefore RepliesTableViewCell doesn't conform to LiveTableViewCellProtocol.

Sign up to request clarification or add additional context in comments.

1 Comment

What about associatedtype?
0

It must specifically be the same as the protocol says. What you're doing is not allowed because it is not the exact same. Remember, you can use as! to make it a RepleisCellObject if you're sure it is.

Comments

0

associatedtype can help here

protocol LiveTableViewCellProtocol: class { associatedtype Data: LiveCellObjectProtocol var data: Data! { get set } } 

Comments

0

You should use associated type

 protocol LiveTableViewCellProtocol: class { associatedtype Object : LiveCellObjectProtocol var data: Object! { get set } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.