Skip to main content

One min read

Reference: Demystify SwiftUI WWDC21

When SwiftUI looks at your code, it will look for three things:

  • Identity
  • Lifetime
  • Dependencies


  • Explicit: In this case, .dogTagID represents the ID of the rescueDog data type which conforms to the Identifiable protocol.

    • With a stable ID, SwiftUI can optimize performance. cleanshot-2024-03-18-000001.jpg
  • Implicit or Structural Identity: If a statement or switch statement in a SwiftUI view's body (@ViewBuilder) creates an implicit ID based on structural differences (i.e., the position of the view relative to its hierarchy).


  • Avoid using AnyView if possible.


View Lifetime

  • State Lifetime == View Lifetime, meaning when the view's identity changes, the state is destroyed along with that identity.



With this implementation, when date < .now, a different view modifier identity is created, which is not stable.


A better version would be to tie the condition in the value of opacity, so there is just a single View Modifier, which means better performance, more correct code, and SwiftUI is optimized for this kind of code.


2 min read

#learning Data Essential in SwiftUI - 2020

  • @State create a new source of truth
  • @Binding create a reference to the source of truth allow write access to that state


Performance consideration: avoid Repeated Heap allocation problem

CleanShot 2024-03-18 at 08.54.28@2x.png|400

CleanShot 2024-03-18 at 08.54.47@2x.png|400

  • @ObservableObject allow multiple SwiftUI view to subscribe to its changes (specifically before the property will change)
  • ObservableObject protocol is for class (reference type only), which mean it will be kept alive in the memory if there is reference to it
  • Class follow this protocol will usually need to have @Published property that will trigger event that ties to SwiftUI view updates
  • ObservableObject can be used to provide a single source of truth through view / app hierarchy
  • @Published can be used to mark property can be observed or bound to (Binding)

CleanShot 2024-03-18 at 10.09.25.jpg

  • ObservableObject can be used to provide a single source of truth through view / app hierarchy, either as a single Instance (one object) or multiple instances CleanShot 2024-03-18 at 10.19.33.jpg

There is 3 way that View can subscribe to changes of @ObservableObjects

  • @ObservedObject, the life cycle of the observed object is not managed by view life cycle, but somewhere else
  • @StateObject , the object is only initiated just before body of the view is created, and destroyed when the view is no longer rendered. In short, life-cycle of the object is managed by the view
  • @EnvironmentObject is usually used when we want to create a globally shared Source of truth

Data Life-cycle

  • Tied to the way we defined it

CleanShot 2024-03-18 at 10.50.31.jpg

  • Scene is new screen or new window instance, think Split view in ipad, windows in macos

3 min read

Last Wednesday, I wanted to experiment with Reddit one more time and see how it went. I tried to post on Reddit a few times, but all of them went cricket 馃.

And to my surprise, This attempt was a great success 馃挭 馃コ.

So this is the traffic during my post on Reddit that went wild.

I got 30x 馃く number of unique visitors compared to a typical boring day. And the avg visit duration is not bad > 1m10s 馃, enough for people to finish seeing essential parts of the landing page.

By the way, here is my product for context: - "Bookmark your article, and listen to them later on your favorite podcast".

And the best thing about this is that it converted to 76 people clicked on Signup, which resulted in a conversion rate of sweet 8.6% (from Landing page -> Sign up page).

Signup conversion rate

And it resulted in 70 new accounts created.

SignUp conversion rate

How It started

It started pretty boringly, depressing even. On Wednesday morning, I felt that my product was a failure; it was not going well (Hint: I still don't know if it's going to be a success or not), and I began to think about buying other people's side projects, which at least validated (have paying users) and had some tractions.

But I know that I need to put on some reps even if I don't want to.

How I felt

How I posted on Reddit

The first step I took was to do some keyword research. As you already know, Reddit is huge, and finding where to post your stuff is quite a challenge in itself because:

  • There are so many subreddits. Each has different requirements for self-promotion
  • Each of them has a different affinity toward each kind of content

My product is pretty niche. And my assumption is that its best customers are people who are interested in consuming long-form content. And even this assumption seems incorrect (more on this in another article.)

Being pragmatic, what I searched for keywords like "listen later", "PodQueue" (similar app) and see where similar content is posted, and I found a few candidates r/longform , r/longread and r/productivityApp, finally r/InternetIsBeatiful

Reddit search

So I went ahead and read through each of sub-reddit rules to adhere to them while also trying to tell a story about how my product was created, hoping to make it exciting enough for people to check it out.

Here is the actual post:

Post on reddit

Focus on what works

After a few hours, posts on LongRead, LongForm, SideProject, ProductivityApp did not gain many upvotes, but... InternetIsBeautiful got quite a lot of views and even positive comments. So I stayed active on that post and answered any comments that came across.

This post on Reddit got 40K+ views after a few hours, and eventually got to 90K+ views.

Reddit post go wild

After that, what I mostly did was to keep responding to comments and messages on Reddit

Lesson learned

To summarize, here are a few lessons I learned:

  • Building a SaaS product is hard, especially the mental aspect of it. You'll always be uncertain whether you should abandon it or keep going.
  • Experiment with posting on different marketing channels, with different wording, perspective, presentations...

Thanks for reading, love to hear your thought and experience with reddit post as well.

If you are interested, follow me on twitter @tuancm

2 min read

It's amazing to start building indies hacker project in 2022, especially with web technology, we have abundance languages, frameworks and app-starters template. But it's also incredibly hard to navigate through these choice.

My goal was to set out to build a website that take in bunch of markdown files from my personal notes then turn it into a Digital Garden, or wiki-style personal knowledge management. Something similar to Obsidian Publish tools, but with more reasonable price and have wider support of markdown editor.

3 min read

I always have this nagging feeling that I need to write blog, to gaining more audience, to have more meaningful relationship, etc but I've never been able to really get to it. I think the main reason is the fear of putting something out there half-baked content, and nobody care about it. Other reason is it's always been a drag to setting up blog post and publishing it.