feedback-assistant / reports

Open collection of Apple Feedback Assistant reports
200 stars 2 forks source link

FB12527597: Previews fail to build with linker error when using SwiftData #407

Open insidegui opened 1 year ago

insidegui commented 1 year ago

Details

What version of Xcode are you using? 15.0 beta 3 (15A5195k)

Did you see an error message? Yes

What was the error? ld: Undefined symbols: unsafeMutableAddressor of self

Description

Xcode fails to build a simple iOS app target for previews when it contains models that use SwiftData’s @Model macro.

Steps to reproduce:

@Model class MySimpleDatabaseModel {
    @Attribute(.unique) var id: String

    init(id: String) { self.id = id }
}

Expected results:

The app preview should compile and run successfully.

Actual results:

The app preview fails to compile with the following linker errors:

ld: Undefined symbols:
  unsafeMutableAddressor of self #1 : PreviewCompileBug.MySimpleDatabaseModel in PreviewCompileBug.MySimpleDatabaseModel.id.init : Swift.String, referenced from:
      PreviewCompileBug.MySimpleDatabaseModel.id.init : Swift.String in DatabaseModels.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Notes:

davesly commented 1 year ago

This seems to be an issue with SwiftData. I was having the same problem, and removing the @Model macro annotation (and associated code) corrected the preview issue. Obviously not ideal, but helps narrow it down.

ViktorEvil commented 1 year ago

can confirm, my app I had converted to SwiftData no longer builds

insidegui commented 1 year ago

Turns out this is listed as a known issue in the Xcode 15 beta 3 release notes:

CleanShot 2023-07-06 at 10 47 03
ViktorEvil commented 1 year ago

Managed to get mine to build (first one took a while), but not being able to use previews is not very convenient at all.

iJustinCabral commented 1 year ago

Can confirm this as well. Can build to simulator and phone with no issue but the preview canvas fails due the @Model macro associated with SwiftData.

davesly commented 1 year ago

Turns out this is listed as a known issue in the Xcode 15 beta 3 release notes:

CleanShot 2023-07-06 at 10 47 03

Good catch! I need to be better in the future about going line-by-line in the release notes. Thanks for pointing this one out!

Max094Reikeb commented 12 months ago

I have the same issue when building the app to place it on my device. Is there a workaround for this to test the app on our devices?

hcri50 commented 12 months ago

having the same problem. What is strange is that I erased the Hard Drive and did a fresh install and then a fresh install of Xcode Beta 3 and right away, I am having the same problem. And again, once I remove @Model the problem goes away

Undefined symbols:

Linker command failed with exit code 1 (use -v to see invocation)

Aparikk commented 12 months ago

Same here :( How can such a major bug slip through? Or is there a way to use SwiftData without the @Model macro?

ViktorEvil commented 12 months ago

Same here :( How can such a major bug slip through? Or is there a way to use SwiftData without the @model macro?

You can use SwiftData but you have to comment out the new #Previews which makes is a bit inconvenient

Aparikk commented 12 months ago

Same here :( How can such a major bug slip through? Or is there a way to use SwiftData without the @model macro?

You can use SwiftData but you have to comment out the new #Previews which makes is a bit inconvenient

Ah… I haven’t tried using the old Preview struct. If this still works, it’s only half as bad.

ViktorEvil commented 12 months ago

not fixed on beta 4

Aparikk commented 12 months ago

Yup and the good old PreviewProvider also does not work :<

Max094Reikeb commented 12 months ago

The issue only appears with @model macro when using SwiftData. Even with old PreviewProvider, it does not work. And beta 4 does not fix the issue... (it is still written as a known issue)

egesucu commented 12 months ago

This has been mentioned in the Xcode 14 beta 4 release notes:

Max094Reikeb commented 12 months ago

This has been mentioned in the Xcode 14 beta 4 release notes:

  • Previewing view code in a SwiftData app results in a linker failure for the canvas despite that code compiling successfully for device and simulator. (111657477) Workaround: Run your app in the simulator to test your UI instead of using Previews.

I tried to run my app on my own iPhone, it still didn't work...

Aparikk commented 12 months ago

This has been mentioned in the Xcode 14 beta 4 release notes:

  • Previewing view code in a SwiftData app results in a linker failure for the canvas despite that code compiling successfully for device and simulator. (111657477)

    Workaround: Run your app in the simulator to test your UI instead of using Previews.

I tried to run my app on my own iPhone, it still didn't work...

Must be something different then. For me both simulator and own device do work.

Max094Reikeb commented 12 months ago

Must be something different then. For me both simulator and own device do work.

Could you show me a quick example, with a simple @model class, with a single view?

ViktorEvil commented 12 months ago

Simulator and devices all work for me but the #Preview code must be commented out or previews disabled in the editor otherwise I get the error

OliveCh12 commented 11 months ago

I also commented out the function to generate the preview #Preview, the error disappears. However, it's not very convenient to rebuild the project every time, especially when making small changes in the interface. Hopefully, someone will fix this issue soon.

OliveCh12 commented 11 months ago

Look's like the problem is solved by installing Xcode 15 beta 5 ✅