Skip to content

The generated initializer doesn't work inside the #Preview macro #26

Open
@kuglee

Description

@kuglee

Description

Thanks for making this macro. I'd like to use it unfortunately the generated initializer doesn't work inside the #Preview macro.

Example:

import SwiftUI
import MemberwiseInit

@MemberwiseInit struct Test {
  let test: Int
}

struct ContentView: View {
  init(test: Test) {}

  var body: some View {
    EmptyView()
  }
}

#Preview {
  ContentView(test: Test(test: 1)) // 🛑 'Test' cannot be constructed because it has no accessible initializers
}

Checklist

  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

I've expected the code above to work.

Actual behavior

The code above doesn't compile: 'Test' cannot be constructed because it has no accessible initializers

Steps to reproduce

No response

swift-memberwise-init-macro version information

main

Destination operating system

macOS 14.1.1

Xcode version information

15.0 (15A240d)

Swift Compiler version information

swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions