Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Mobile Programming Protocol Extension

Mobile Programming Protocol Extension

MobileProgrammingの授業で使うスライドです!

yuichiro_takahashi

January 29, 2019
Tweet

More Decks by yuichiro_takahashi

Other Decks in Technology

Transcript

  1. ςΩετ EXTENSION(จ๏) extension String { var length: Int { return

    self.count } } Ωʔϫʔυ extension ʹଓ͚ͯ ֦ு͍ͨ͠Class໊Λࢦఆ PropertyΛ௥ՃͰ͖Δ͕ Computed Property ͷΈ
  2. ςΩετ EXTENSION(จ๏) extension String { var length: Int { return

    self.count } func toInt(with defaultValue: Int) -> Int { return Int(self) ?? defaultValue } } Ωʔϫʔυ extension ʹଓ͚ͯ ֦ு͍ͨ͠Class໊Λࢦఆ PropertyΛ௥ՃͰ͖Δ͕ Computed Property ͷΈ ϝιου͸ClassͳͲͱಉ͡Α͏ʹ௥ՃՄೳ
  3. ςΩετ EXTENSION(จ๏) extension String { var length: Int { return

    self.count } func toInt(with defaultValue: Int) -> Int { return Int(self) ?? defaultValue } init(date: Date, format: String) { // ௕͘ͳΔͷͰׂѪ } } Ωʔϫʔυ extension ʹଓ͚ͯ ֦ு͍ͨ͠Class໊Λࢦఆ PropertyΛ௥ՃͰ͖Δ͕ Computed Property ͷΈ ϝιου͸ClassͳͲͱಉ͡Α͏ʹ௥ՃՄೳ ΠχγϟϥΠβ΋ClassͳͲͱಉ͡Α͏ʹ௥ՃՄೳ
  4. ςΩετ PROTOCOL EXTENSION(จ๏, ఆٛ) protocol DismissDelegate {} extension DismissDelegate {

    } ·ͣ͸ProtocolΛఆٛ͢Δ͕֦ு͍ͨ͠ϝιου͸ͬͪ͜ʹ͸ॻ͔ͳ͍ extension Ωʔϫʔυʹଓ͚ͯProtocol໊Λࢦఆ
  5. ςΩετ PROTOCOL EXTENSION(จ๏, ఆٛ) protocol DismissDelegate {} extension DismissDelegate {

    func dismiss(vc: UIViewController) { vc.dismiss(animated: true, completion: nil) } } ·ͣ͸ProtocolΛఆٛ͢Δ͕֦ு͍ͨ͠ϝιου͸ͬͪ͜ʹ͸ॻ͔ͳ͍ extension Ωʔϫʔυʹଓ͚ͯProtocol໊Λࢦఆ ֦ு͍ͨ͠ϝιουΛ࣮૷
  6. ςΩετ PROTOCOL EXTENSION(จ๏, ࠾༻ଆ) class ViewController: UIViewController { } extension

    ViewController: DismissDelegate {} ֦ுͨ͠ProtocolΛ࠾༻ͤ͞Δ͕࣮૷Λॻ͘ඞཁ͕ແ͍ʂʂ
  7. ςΩετ PROTOCOL EXTENSION(จ๏, ࠾༻ଆ) class ViewController: UIViewController { @IBAction func

    dismissAction(_ sender: UIButton) { dismiss(vc: self) } } extension ViewController: DismissDelegate {} ֦ுͨ͠ProtocolΛ࠾༻ͤ͞Δ͕࣮૷Λॻ͘ඞཁ͕ແ͍ʂʂ DismissDelegateͷextensionͷ࣮૷͕ݺ͹ΕΔ