NEW: Learn to build amazing SwiftUI apps for macOS with my new book! >>

Question: Is it just a matter of CONVENTION to use the same name of property's as the names of init () parameter's ?

Forums > 100 Days of SwiftUI

This has been confusing me for ages.

From what I see, it only creates confusions for newbies like me.

If we don't have this convention, we don't even need to use self.propertyname , right ? self. here is for differentiating the property and the parameter, right ? If these two names are different, problem solved, no ?

Or there's some good reasons behind this appraoch ?

Thank you in advance



I think you're right; there's nothing stopping you from using different property names than function/method names. Sometimes it can be difficult to think of good names though - especially when the variables mean the same thing. This is particularly true with initializers, where the parameter's only purpose is to set the property value.


Yep, just convention, though a useful one IMO because it makes it 100% clear how the parameters are being used in the data structure. And, as @ty-n-42 mentions, it can be difficult to come up with good names that aren't already the name of the properties those parameters will be assigned to. And why make life more difficult for yourself?


Hacking with Swift is sponsored by RevenueCat

SPONSORED Spend less time managing in-app purchase infrastructure so you can focus on building your app. RevenueCat gives everything you need to easily implement, manage, and analyze in-app purchases and subscriptions without managing servers or writing backend code.

Get Started

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.