Upgrade to Pro — share decks privately, control downloads, hide ads and more …

addObserver: から考える API インタフェース

addObserver: から考える API インタフェース

NSNotificationCenter の addObserver が iOS9 から removeObserver しなくて良くなったので API の対称性から外れてしまったお話です

755ef9f11988a69b0124ea6058119d84?s=128

KAMEDAkyosuke

December 18, 2017
Tweet

Transcript

  1. BEE0CTFSWFS͔Βߟ͑ Δ"1*ΠϯλϑΣʔε  ,":"$ٕज़෦ ُాژհ

  2. ࣗݾ঺հ w ,".&%"LZPTVLF w UXJUUFS!(FNNCV w UXJUDI!,".&%"LZPTVLF w J04"OESPJE&OHJOFFS w

    ࠇຐज़ಘҙ
  3. J04͔Β/4/PUJpDBUJPO$FOUFSͷ SFNPWF0CTFSWFS͠ͳͯ͘΋ྑ͘ͳͬ ͨͬͯ࿩ฉ͍ͨ͜ͱ͋Γ·͢ΑͶʁ BOESPJEͷํ͸#SPBEDBTUͷSFHJTUFS3FDFJWFSͨ͠ޙʹVOSFHJTUFS3FDFJWFS͠ͳͯ͘ྑ ͘ͳͬͨͱࢥ͍͚ͬͯͨͩΕ͹େৎ෉Ͱ͢ɻ

  4. υΩϡϝϯτ BEE0CTFSWFSTFMFDUPSOBNFPCKFDU %JTDVTTJPO *GZPVSBQQUBSHFUTJ04BOEMBUFSPSNBD04 BOEMBUFS ZPVEPOUOFFEUPVOSFHJTUFSBOPCTFSWFSJO JUTEFBMMPDNFUIPE SFGTIUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOGPVOEBUJPOOTOPUJpDBUJPODFOUFS BEEPCTFSWFS MBOHVBHFPCKD

  5. ϦϦʔεϊʔτ /4/PUJpDBUJPO$FOUFS *O049BOEJ04/4/PUJpDBUJPO$FOUFSBOE /4%JTUSJCVUFE/PUJpDBUJPO$FOUFSXJMMOPMPOHFSTFOE OPUJpDBUJPOTUPSFHJTUFSFEPCTFSWFSTUIBUNBZCF EFBMMPDBUFE CMBICMBICMBI SFGTIUUQTEFWFMPQFSBQQMFDPNMJCSBSZDPOUFO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4/PUJpDBUJPO$FOUFSͷBEE0CTFSWFS͸ SFNPWF0CTFSWFS͠ͳͯ͘΋ྑ͘ͳ͚ͬͨͲɺϓϩάϥϛ ϯάͷ͓࡞๏ͱͯ͠͸ྑ͘ͳ͍ʂʂ

  24. /4/PUJpDBUJPO$FOUFS ͦΕҎ֎ͷΫϥε SFNPWF0CTFSWFS͠ͳ͍ ໰୊ͳ͠ ໰୊͋Γ SFNPWF0CTFSWFS͢Δ ໰୊ͳ͠ ໰୊ͳ͠ දʹ͢Δͱ

  25. ࢲͨͪͷνʔϜͰ͸ w SFHJTUFSVOSFHJTUFS BEESFNPWF0CTFSWFS ͸͓࡞๏ w /4/PUJpDBUJPO$FOUFS͚ͩྫ֎ͷঢ়ଶͰ͸Ή͠ΖଞͷΫ ϥεͰؒҧ͑ΔڪΕ͕͋Δ w ͳͷͰSFNPWF0CTFSWFSΛৗʹॻ͘ํ਑ʹͱ͍͏͔

    BEE0CTFSWFS'PS/BNFPCKFDURVFVFVTJOH#MPDLΛ࢖ ͏͜ͱʹ
  26. ·ͱΊ w "1*ͷΠϯλϑΣʔε͸ͦΕࣗ਎͚ͩͰͳ͘ଞͷΫϥε΍ ϑϨʔϜϫʔΫ౳͔ΒܾΊΔ΂͖ w ͳͷͰɺ͋Δ"1*ͷ࢖༻ํ๏͕มΘ͔ͬͨΒͱ͍ͬͯଞ ͷΫϥεͱͷؔ࿈ʹ஫ҙ͢΂͖ w ͦͷ্Ͱࣗ෼ͷϓϩδΣΫτʹͲ͏औΓ૊Ή͔ܾΊ·͠ΐ ͏