For SwiftUI custom parameter-less view modifier: choosing which syntax: .blah vs. .blah()

How to decide which one to use?

Conflicting examples:

Date.now vs. DispatchTime.now()

Is there simple way to decide which way to go? For SwiftUI view modifier, they are all non-mutating and returns a new view.

1 Like

What are you trying to ask?

Which form to use:

someView
    .myModifierAsVar
// or
someView
    .myModifierAsFunc()

I can write the modifier either as a var getter or as a func. I want to know how to decide which way to go?

What you must be referring to here is a computed get-only property. All the SwiftUI modifiers I've seen are written as functions, so I suggest you write a function for your view modifier.

1 Like