SwiftLee
Read post

Memberwise Initializer in Swift explained with Code Examples

Swift automatically generates memberwise initializers for structs, letting you skip writing boilerplate init code. Swift 6.4 (SE-0502) improves this by excluding private stored properties that already have a default value from the generated initializer. Before this change, a private property with a default value would make the entire memberwise initializer private, forcing developers to write manual initializers. Now, such properties are treated as implementation details and omitted. The rule: a property is excluded only when it is less accessible than the generated initializer AND already has an initial value. Private properties without default values still appear in the initializer. Public structs still require explicit public initializers regardless of this change. A source compatibility overload preserves existing code that initializes private properties through the old synthesized initializer.

    #swift
Jun 29•8m read time•From avanderlee.com
Post cover image
Table of contents
What is a memberwise initializer?Default property valuesPrivate properties before Swift 6.4Private properties in Swift 6.4Which properties are excluded?Public structs still need explicit initializersSource compatibilityWhy this change mattersConclusion
339 Impressions
SwiftLee's image
SwiftLee

Avanderlee is a blog and resource hub for iOS development, offering tutorials, tips, and insights fo...

173 Followers

•

249 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard