Pebble Coding

ソフトウェアエンジニアによるIT技術、数学の備忘録

swift タイプエイリアス

Type Aliases

typealias AudioSample = UInt16

プロトコルのAssociated Typeには特定のプロトコルに準拠することという条件を付けられる。

protocol PBProtocol {
    typealias PBError: IntegerType
}
class PBClass: PBProtocol {
    typealias PBError = Int
}

IntegerTypeに準拠しない場合はPBProtocolを使おうとすると
Type PBClass does not conform to protocol 'PBProtocol
というコンパイルエラーになる。

f:id:pebble8888:20160304084016p:plain