Use Typealias as an alias for a common data type,
On the one hand it is easier to understand the use of this type by alias,
On the other hand, you can reduce the amount of code you develop daily.
Typealias Usage Examples:
//Network request common callback closureTypealias successwithmsg = ((_ msg:string)Void) Typealias failwitherror= (Error)Void)//connect multiple protocols with &Typealias Uitableviewcommonprotocol = uitableviewdelegate &Uitableviewdatasourceclasstestdelegate:uitableviewcommonprotocol{Func TableView (_ Tableview:uitableview, Numberofrowsinsection section:i NT)-Int {return 0} func TableView (_ Tableview:uitableview, Cellforrowat Indexpath:indexpath)-UITableViewCell {Let cell= Tableview.dequeuereusablecell (withidentifier:"Cell") returnCell}}
When defining a protocol, you can use Associatedtype to implement generics
Associatedtype Use instances
protocol associatedtypetestprotocol{ associatedtype T func AppendData (_ data:[t]) func ResetData (_ Data:[t])}class associatedtypetestview:associatedtypetestprotocol{ // Specify the specific type when implementing the Protocol}// must be consistent with the type of the method above }}
Ficow Original, reproduced please specify the source:http://www.cnblogs.com/ficow/p/8227701.html
Swift Typealias Associatedtype