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

[社内勉強会]Parchment-swiftの実装説明

k-kohey
March 08, 2022
93

 [社内勉強会]Parchment-swiftの実装説明

自身が作成したライブラリをプロダクトに導入していくにあたって、メンバに実装を共有するために作った資料の一部です

k-kohey

March 08, 2022
Tweet

Transcript

  1. γεςϜߏ੒ ॲཧͷྲྀΕΛදͨ͠ਤ -PHHFS#VOEMFS -PHHFS" -PHHFS$ -PHHFS# &WFOU &WFOU &WFOU %JTQBUDI

    &WFOU &WFOU &WFOU σϑΥϧτͰ ̍෼͝ͱʹ ϙʔϦϯά 4DIFEVMFS &WFOU &WFOU όοΫΤ ϯυ" &WFOU όοΫΤ ϯυ# &WFOU Πϕϯτൃੜ &WFOU .VUBUJPO &WFOU \ FWFOUlVTFS$SFBUFEz  QSPQFSUJFT\ lOBNFzl5BSPz  l04zlJ04z  l7FSTJPOzlz  l.PEFMzlJ1IPOF9z ^ ^ \ FWFOUlVTFS$SFBUFEz  QSPQFSUJFT\ lOBNFzl5BSPz ^ ^ logger.send(.createdUser(“Taro”))
  2. ΠϯλϑΣʔε let logger = LoggerBundler( components: [MyLogger()] ) logger.send(.implession(“home")) //

    enumͰ΋OK extension TrackingEvent: Loggable { static func implession(_ screen: String) -> Self { TrackingEvent(eventName: "imp", parameters: ["screen": screen]) } } extension LoggerComponentID { static let my: Self = .init("My") } struct MyLogger: LoggerComponent { static var id: LoggerComponentID = .my func send(_ log: [LoggerSendable]) async -> Bool { print("send \(log)") return true } } όοΫΤϯυ΁ϩάΛૹ৴͢Δ -PHHFS$PNQPOFOUΛ࣮૷ ϩά৘ใΛ٧ΊΔ5ZQFΛ -PHHBCMFʹ४ڌͯ͠ఆٛ TFOEϝιουΛ௨ͯ͠ &WFOUΛૹ৴
  3. ओཁͳ5ZQF -PHHFS#VOEMFS w ϩάૹ৴ͷ஥հ໾ w ड͚औͬͨΠϕϯτΛ -PHHFS$PNQPOFOUୡʹ഑৴͢Δ w ड͚औͬͨΠϕϯτΛ#V ff

    FSʹૹΔ͔ɺ -PHHFSʹૹΔ͔Λܾఆ͢Δ -PHHFS#VOEMFS -PHHFS -PHHFS -PHHFS &WFOU &WFOU &WFOU %JTQBUDI &WFOU &WFOU &WFOU
  4. ओཁͳ5ZQF #V ff FSFE&WFOU'MVTI4DIFEVMFS w #V ff FS͔ΒͲ͏͍͏৚݅ͰཷΊࠐΜͩΠϕ ϯτΛर্͍͛Δ͔Λܾఆ͢Δ໾ׂ w

    ͜ͷ৚݅͸ෳࡶʹͳΓ͕ͪͰ͋Γɺॊೈ ੑΛٻΊΒΕΔ෦෼ w Ҿ਺ʹ#V ff FS͕౉͞ΕΔͷͰɺ೚ҙͷ৚݅ ͷ࣌ʹEFRVFVFͯ͠-PHHFSʹ౉͢ w σϑΥϧτͰ͸̍෼ຖʹϙʔϦϯά͢Δ࣮ ૷͕-PHHFSʹ%*͞ΕΔ public protocol BufferedEventFlushScheduler { func schedule( with buffer: TrackingEventBufferAdapter, didFlush: @escaping ([BufferRecord])->() ) } -PHHFS#VOEMFS 4DIFEVMFS &WFOU &WFOU ̽ඵຖʹ &WFOUΛLݸ ٵ্͍͛Δɺ ౳ &WFOU &WFOU &WFOU
  5. ओཁͳ5ZQF .VUBUJPO w ͋ΔΠϕϯτΛผͷΠϕϯτ΁มԽͤ͞Δ ໾ׂ w ҉໧తʹ04৘ใ΍σόΠε໊ΛΠϕϯτ ʹ෇Ճ͢ΔͨΊʹ༻ҙͨ͠ w ӈਤʢԼʣͷΑ͏ͳ5ZQFΛએݴ͓͚ͯ͠͹

    উखʹύϥϝʔλʹ௥Ճ͞ΕΔ࢓૊Έ public struct DeviceDataMutation: Mutation { private let deviceParams = [ "Model": UIDevice.current.name, "OS": UIDevice.current.systemName, "OS Version": UIDevice.current.systemVersion ] public func transform( _ event: Loggable, id: LoggerComponentID ) -> Loggable { let log: LoggableDictonary = [ \.eventName: event.eventName, \.parameters: event.parameters.merging(deviceParams) { left, _ in left } ] return log } } -PHHFS .VUBUJPO &WFOU &WFOU -PHHFS#VOEMFS \ lPTzlJ04z  l.PEFMz lJ1IPOFz  lVTFSz5BSP ^ \ lVTFSz5BSP ^ 1BSBNFUFST