How can I make the memberwise initialiser public, by default, for structs in Swift?

Quoting the manual:

"Default Memberwise Initializers for Structure Types The default memberwise initializer for a structure type is considered private if any of the structure’s stored properties are private. Otherwise, the initializer has an access level of internal.

As with the default initializer above, if you want a public structure type to be initializable with a memberwise initializer when used in another module, you must provide a public memberwise initializer yourself as part of the type’s definition."

Excerpt from "The Swift Programming Language", section "Access Control".


While it is not possible to have the default memberwise initializer at least you can make one quickly with the following steps:

UPDATE: Xcode 11 and later

As mentioned by Brock Batsell on the comments, for Xcode 11 and later all you need to is this:

  • Right click the class or struct name and choose refactor -> Generate Memberwise Initializer

Xcode 10 and earlier answer

  1. Make the object a class temporarily instead of a struct
  2. Save
  3. Right click the class name and choose refactor -> Generate Memberwise Initializer
  4. Change it back to a struct