} var ability: Ability { get } var level: Int { get set } var health: Int { get set } func displayStatus() func doAbility<T: Pokemon>(to pokemon: T) } Protocol Ωʔϫʔυ͔Β࢝·Δ
} var ability: Ability { get } var level: Int { get set } var health: Int { get set } func displayStatus() func doAbility<T: Pokemon>(to pokemon: T) } Protocol Ωʔϫʔυ͔Β࢝·Δ ͜͜ඞͣvarͰఆٛ͢Δ
} var ability: Ability { get } var level: Int { get set } var health: Int { get set } func displayStatus() func doAbility<T: Pokemon>(to pokemon: T) } Protocol Ωʔϫʔυ͔Β࢝·Δ ͜͜ඞͣvarͰఆٛ͢Δ ۩ମతͳΛࢦఆ͢ΔΘΓʹ ಡΈॻ͖ͷઃఆΛ͢Δ ͜Ε get ͚ͩͳͷͰಡΈࠐΈઐ༻
} var ability: Ability { get } var level: Int { get set } var health: Int { get set } func displayStatus() func doAbility<T: Pokemon>(to pokemon: T) } Protocol Ωʔϫʔυ͔Β࢝·Δ ͜͜ඞͣvarͰఆٛ͢Δ ۩ମతͳΛࢦఆ͢ΔΘΓʹ ಡΈॻ͖ͷઃఆΛ͢Δ ͜Ε get ͚ͩͳͷͰಡΈࠐΈઐ༻ ͪ͜Β get set ྆ํͷهड़͕͋ΔͷͰ ಡΈॻ͖Մೳ
} var ability: Ability { get } var level: Int { get set } var health: Int { get set } func displayStatus() func doAbility<T: Pokemon>(to pokemon: T) } Protocol Ωʔϫʔυ͔Β࢝·Δ ͜͜ඞͣvarͰఆٛ͢Δ ۩ମతͳΛࢦఆ͢ΔΘΓʹ ಡΈॻ͖ͷઃఆΛ͢Δ ͜Ε get ͚ͩͳͷͰಡΈࠐΈઐ༻ ͪ͜Β get set ྆ํͷهड़͕͋ΔͷͰ ಡΈॻ͖Մೳ ϝιου໊લͱҾɺΓ͚ͩΛهड़͠۩ମతͳ࣮ॻ͔ͳ͍
ability: Ability var level: Int var health: Int func displayStatus() { print("name: \(self.name)") print("Lv: \(self.level)") print("HP: \(self.health)") } func doAbility<T>(to pokemon: T) where T : Pokemon { // to be continue... } } ࠾༻͍ͨ͠ProtocolΛࢦఆ͢Δ
ability: Ability var level: Int var health: Int func displayStatus() { print("name: \(self.name)") print("Lv: \(self.level)") print("HP: \(self.health)") } func doAbility<T>(to pokemon: T) where T : Pokemon { // to be continue... } } ࠾༻͍ͨ͠ProtocolΛࢦఆ͢Δ ͜ͷೋͭఆٛͷ࣌ʹ get ͚ͩͩͬͨͷͰ let Ͱఆͱͯ͠ఆٛ(Read only)
ability: Ability var level: Int var health: Int func displayStatus() { print("name: \(self.name)") print("Lv: \(self.level)") print("HP: \(self.health)") } func doAbility<T>(to pokemon: T) where T : Pokemon { // to be continue... } } ࠾༻͍ͨ͠ProtocolΛࢦఆ͢Δ ͜ͷೋͭఆٛͷ࣌ʹ get ͚ͩͩͬͨͷͰ let Ͱఆͱͯ͠ఆٛ(Read only) ͜ͷೋͭఆٛͷ࣌ʹ get set ྆ํࢦఆͨ͠ͷͰ var Ͱมͱͯ͠ఆٛ(Read/Write)
ability: Ability var level: Int var health: Int func displayStatus() { print("name: \(self.name)") print("Lv: \(self.level)") print("HP: \(self.health)") } func doAbility<T>(to pokemon: T) where T : Pokemon { // to be continue... } } ࠾༻͍ͨ͠ProtocolΛࢦఆ͢Δ ͜ͷೋͭఆٛͷ࣌ʹ get ͚ͩͩͬͨͷͰ let Ͱఆͱͯ͠ఆٛ(Read only) ͜ͷೋͭఆٛͷ࣌ʹ get set ྆ํࢦఆͨ͠ͷͰ var Ͱมͱͯ͠ఆٛ(Read/Write) ϝιουఆٛͯ͋͠ΔҾΓΛهड़ͯ͠தΛ࣮͢Δ
{ get } var ability: Ability { get } var level: Int { get set } var health: Int { get set } func displayStatus() func doAbility<T: Pokemon>(to pokemon: T) } // Protocol࠾༻ struct Pikachu: Pokemon { let name: String let ability: Ability var level: Int var health: Int func displayStatus() { print("name: \(self.name)") print("Lv: \(self.level)") print("HP: \(self.health)") } func doAbility<T>(to pokemon: T) where T : Pokemon { // to be continue... } }