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

個人開発をTCAで運用していくということ.pdf

entaku
March 18, 2024
830

 個人開発をTCAで運用していくということ.pdf

entaku

March 18, 2024
Tweet

Transcript

  1. ػೳʹ߹ΘͤͯTCAͷΞΫγϣϯΛ ઃܭ enum Action: Equatable { case audioPlayerClient(TaskResult<Bool>, PlaybackMode) case

    delegate(Delegate) case playButtonTapped case timerUpdated(TimeInterval) case titleTextFieldChanged(String) case onTapPlaySpeed case skipBy(TimeInterval) case toggleLoop } • Ի੠λΠτϧมߋ • ࠶ੜػೳ • ϧʔϓػೳ • 10ඵεΩοϓ/10ඵר͖໭͠ • ഒ଎ػೳ • Ի੠ϑΝΠϧγΣΞ ͜Ε͸ແ͍ͷͰޙͰઆ໌͠·͢
  2. Ұ෦ͷॲཧ͸Action΍ଞ͔Βݺͼ ग़͞ΕΔઃఆʹͳ͍ͬͯ·͢ enum Action: Equatable { case audioPlayerClient(TaskResult<Bool>, PlaybackMode) case

    delegate(Delegate) case playButtonTapped case timerUpdated(TimeInterval) case titleTextFieldChanged(String) case onTapPlaySpeed case skipBy(TimeInterval) case toggleLoop } • AudioPlayer͔ΒͷDelegateॲཧ • Ұཡը໘΁ͷDelegateॲཧ • ࠶ੜதͷ࣌ؒߋ৽ॲཧ
  3. case .playButtonTapped: switch state.mode { case .notPlaying: state.mode = .playing(progress:

    state.time / state.duration) return .run { [ url = state.url, time = state.time, playSpeed = state.playSpeed, isLoop = state.isLooping ] send in await send(.delegate(.playbackStarted)) async let playAudio: Void = send( .audioPlayerClient(TaskResult { try await self.audioPlayer.play(url, time, playSpeed, isLoop) }, .aut ) for await _ in self.clock.timer(interval: .milliseconds(500)) { let time = try await self.audioPlayer.getCurrentTime() await send(.timerUpdated(time)) } await playAudio }.cancellable(id: CancelID.play, cancelInFlight: true) Ի੠࠶ੜػೳͷྲྀΕ 1.࠶ੜঢ়ଶͷมߋ
  4. Ի੠࠶ੜػೳͷྲྀΕ case .playButtonTapped: switch state.mode { case .notPlaying: state.mode =

    .playing(progress: state.time / state.duration) return .run { [ url = state.url, time = state.time, playSpeed = state.playSpeed, isLoop = state.isLooping ] send in await send(.delegate(.playbackStarted)) async let playAudio: Void = send( .audioPlayerClient(TaskResult { try await self.audioPlayer.play(url, time, playSpeed, isLoop) }, .autom ) for await _ in self.clock.timer(interval: .milliseconds(500)) { let time = try await self.audioPlayer.getCurrentTime() await send(.timerUpdated(time)) } await playAudio }.cancellable(id: CancelID.play, cancelInFlight: true) 1.࠶ੜঢ়ଶͷมߋ 2.ඇಉظͰAudioPlayerΛ࣮ߦ
  5. Ի੠࠶ੜػೳͷྲྀΕ case .playButtonTapped: switch state.mode { case .notPlaying: state.mode =

    .playing(progress: state.time / state.duration) return .run { [ url = state.url, time = state.time, playSpeed = state.playSpeed, isLoop = state.isLooping ] send in await send(.delegate(.playbackStarted)) async let playAudio: Void = send( .audioPlayerClient(TaskResult { try await self.audioPlayer.play(url, time, playSpeed, isLoop) }, .autom ) for await _ in self.clock.timer(interval: .milliseconds(500)) { let time = try await self.audioPlayer.getCurrentTime() await send(.timerUpdated(time)) } await playAudio }.cancellable(id: CancelID.play, cancelInFlight: true) 1.࠶ੜঢ়ଶͷมߋ 2.ඇಉظͰAudioPlayerΛ࣮ߦ 3.Ұཡը໘΁Ի੠͕ 
 ։࢝ͨ͜͠ͱΛ௨஌
  6. Ի੠࠶ੜػೳͷྲྀΕ 1.࠶ੜঢ়ଶͷมߋ 2.ඇಉظͰAudioPlayerΛ࣮ߦ 3.Ұཡը໘΁Ի੠͕ 
 ։࢝ͨ͜͠ͱΛ௨஌ case .playButtonTapped: switch state.mode

    { case .notPlaying: state.mode = .playing(progress: state.time / state.duration) return .run { [ url = state.url, time = state.time, playSpeed = state.playSpeed, isLoop = state.isLooping ] send in await send(.delegate(.playbackStarted)) async let playAudio: Void = send( .audioPlayerClient(TaskResult { try await self.audioPlayer.play(url, time, playSpeed, isLoop) }, .autom ) for await _ in self.clock.timer(interval: .milliseconds(500)) { let time = try await self.audioPlayer.getCurrentTime() await send(.timerUpdated(time)) } await playAudio }.cancellable(id: CancelID.play, cancelInFlight: true) 4.AudioPlayerΛ࣮ߦ͠ 
 ݁ՌΛaudioPlayerClientʹ౉͢
  7. Ի੠࠶ੜػೳͷྲྀΕ 1.࠶ੜঢ়ଶͷมߋ 2.ඇಉظͰAudioPlayerΛ࣮ߦ 3.Ұཡը໘΁Ի੠͕ 
 ։࢝ͨ͜͠ͱΛ௨஌ case .playButtonTapped: switch state.mode

    { case .notPlaying: state.mode = .playing(progress: state.time / state.duration) return .run { [ url = state.url, time = state.time, playSpeed = state.playSpeed, isLoop = state.isLooping ] send in await send(.delegate(.playbackStarted)) async let playAudio: Void = send( .audioPlayerClient(TaskResult { try await self.audioPlayer.play(url, time, playSpeed, isLoop) }, .autom ) for await _ in self.clock.timer(interval: .milliseconds(500)) { let time = try await self.audioPlayer.getCurrentTime() await send(.timerUpdated(time)) } await playAudio }.cancellable(id: CancelID.play, cancelInFlight: true) 4.AudioPlayerΛ࣮ߦ͠ 
 ݁ՌΛaudioPlayerClientʹ౉͢ 5.playAudio͕ऴΘΔ·Ͱtimer 
 Λߋ৽
  8. TCAͷதͰTimerͷॲཧΛࢸΔॴͰݺͼग़͠ ͍ͯΔ🤗 for await _ in self.clock.timer(interval: .milliseconds(500)) { let

    time = try await self.audioPlayer.getCurrentTime() await send(.timerUpdated(time)) } • Ի੠λΠτϧมߋ • ࠶ੜػೳ • ϧʔϓػೳ • 10ඵεΩοϓ/10ඵר͖໭͠ • ഒ଎ػೳ • Ի੠ϑΝΠϧγΣΞ
  9. ʮԻ੠ϑΝΠϧγΣΞʯ͸TCA࢖Θͣʹଥڠͯ͠ ·͢🤗 .navigationBarItems(trailing: Button(action: { // γΣΞ͢ΔίϯςϯπΛઃఆ let textToShare =

    viewStore.title var itemsToShare: [Any] = [textToShare] let inputDocumentsPath = NSHomeDirectory() + "/Documents/" + viewStore.url.lastPathComponent let audioFileURL = NSURL(fileURLWithPath: inputDocumentsPath) itemsToShare.append(audioFileURL) // UIActivityViewControllerΛදࣔ let activityViewController = UIActivityViewController(activityItems: itemsToShare, applicationActivities: nil) UIApplication.shared.windows.first?.rootViewController?.present(activityViewController, animated: true, completion: nil) }) { Image(systemName: "square.and.arrow.up") } )
  10. ࣗݾ঺հ • Name: entaku • Job: iOSΤϯδχΞ / AndroidΤϯδχΞ •

    Hobby: • ԻָϑΣε؍ઓ(ࠓ೥͸JapanJam2ճߦͥ͘ʂ) • ݸਓ։ൃ • Career: • SIer໿6೥ • εϙʔπϚονϯάΞϓϦ1೥ • ෺ྲྀITαʔϏε ໿2೥ • Voicy 2೥ X