Flow vs SharedFlow

what is Flow?

Flow is an interface , its just emit value it doesn't store any value on screen rotation it will be started from first. we use flow if you want to emit any api response to view or any multiple emit need to be done.

Example of Flow

And collecting that response inside view using corroutine scope

what is SharedFlow?

SharedFlow is also a flow it doesnt keep a value with it so only in below example we are not passing any value to it for the variaable _onJoinEvent.They will send event if they are no collectors for them.Mostly sharedflow are used to send one time event it will send the same value if already sent by it not like stateflow.It doesnt emit the last value on screen rotation but in stateflow it will be updated with last value.

And inside view we can call

We use flow when we want to emit multiple things and for one time event its good to use sharedflow.

Knowledge is everything.Check out my app at https://play.google.com/store/apps/details?id=com.vibe.britevibe

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Check if a Swift Array Is Empty: Best Practice Revisited

[LeetCode] 1431. Kids With the Greatest Number of Candies (Swift)

What Is Hashable in Swift?

Set Custom Text Sizes on a Per-App Basis in iOS 15

SDFX — Basic step-by-step filtering of images: Opening, Filtering, and Saving or Sharing the result.

Tutorial: From Sketch to Xcode — Adding a Tab Bar

How to change a State variable value when app lifecycle changes in SwiftUI ?

Unused code cleanup in iOS projects

Photo by pan xiaozhen on Unsplash

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pandiyan Mani

Pandiyan Mani

Knowledge is everything.Check out my app at https://play.google.com/store/apps/details?id=com.vibe.britevibe

More from Medium

Highlight text search on RecycleView with Databinding and Kotlin Flow

Koin Framework — Scopes(part-7) — Most Underrated Framework🤔

Jetpack navigation: Pitfalls and recommendations

Getting prepared for Jetpack Compose

Jetpack Compose Tutorial