Just in Swift

Get an Idea About Combine with UIKit

Tolga Taner
1 min readJan 8, 2023
Photo by Brett Jordan on Unsplash

Just is a struct that gets a generic value in its initialization for using asynchronous programming namely Combine. It only emits its value once to subscriber and it is finished so it is known as Publisher, too. Let’s define a basic property using Just and after we will see that how we set Just for more complex scenario.

When we look at the example, sink() will always print out the console as “hey” even if we manipulate it’s value after initialization.

Therefore, we can use Just as a constant value to assign all properties that is changes once. For instance, cornerRadius, backgroundColor, textColor of an user interface element. Let’s dive deep and see the source code.

To achieve that, we will define a textColor of a title label inside related view model scope for our announcements screen.

and then, we will assign the property to corresponding to the label in viewDidLoad.

That’s all, we used Just effectively. It is only useful at once subscription so I think constant assignees are suitable more than other publishers.

Thanks for reading!

--

--