I'm trying to define a
// The typealias definition
typealias CellDelegate = AnyObject<UIPickerViewDataSource, UIPickerViewDelegate>
// In my UITableViewCell subclass:
weak var delegate: CellDelegate?
The code that you posted has a different meaning from what you'd expect. You're treating
AnyObject like a generic type, with
UIPickerViewDelegate as type arguments. It's the same thing as creating a
Int keys and
String values, for example:
var someDictionary: Dictionary<Int, String>
What you're trying to accomplish needs a different construct, called protocol composition. Swift provides it specifically to express types that conforms to multiple protocols. Its syntax is the following, you can use it anywhere you can use regular types:
protocol<FirstProtocol, SecondProtocol, ...>
Using this feature, your code would become:
// The typealias definition typealias CellDelegate = protocol<UIPickerViewDataSource, UIPickerViewDelegate> // In my UITableViewCell subclass: weak var delegate: CellDelegate?
Protocol composition is explained in Apple's guide to the Swift language, here.