Grdb.swift: Crash when saving records with Xcode 11.2

Created on 1 Nov 2019  路  8Comments  路  Source: groue/GRDB.swift

When your app:

  • is compiled with Xcode 11.2
  • embeds GRDB as a Swift Package
  • attempts at inserting or updating a Codable record

It crashes.

This is due to a bug somewhere in the Xcode 11.2 toolkit, which has been reported on October, 20 as https://bugs.swift.org/browse/SR-11643.


EDIT: SEE THIS COMMENT FOR A WORKAROUND.

The rest of this comment is now obsoleted. Leaving it for posterity.


There are few known workarounds today:

  1. Don't embed GRDB as a Swift Package. There are other installation methods.
  2. Or provide an explicit implementation of the encode(to:) method.

    For example, assuming you already have the definition of a Codable Record type as below:

    struct Player: Codable, /* Record protocols */ {
        var id: Int64
        var name: String
        var score: Int
    
        enum Columns {
            static let id = Column(CodingKeys.id)
            static let name = Column(CodingKeys.name)
            static let score = Column(CodingKeys.score)
        }
    }
    

    Add:

    // Workaround for the crash
    extension Player {
        func encode(to container: inout PersistenceContainer) {
            container[Columns.id] = id
            container[Columns.name] = name
            container[Columns.score] = score
        }
    }
    

If you happen to have time to give back to GRDB, here are a few other actions you can take right now:

  • Report your application crash to http://feedbackassistant.apple.com. Do your best, provide stack traces, etc.
  • Contribute and help finding a workaround that is less brutal for GRDB users than the ones listed above.

Thank you,
Gwendal Rou茅

support

Most helpful comment

We found a workaround.

Set聽DEAD_CODE_STRIPPING = NO in the app鈥檚 target fixes the crash.

All 8 comments

The Swift team knows about the issue: https://bugs.swift.org/browse/SR-11564

We found a workaround.

Set聽DEAD_CODE_STRIPPING = NO in the app鈥檚 target fixes the crash.

Set聽DEAD_CODE_STRIPPING = NO in the app鈥檚 target fixes the crash.

Confirmed 馃憤

This is done in Build Settings tab of the application target: search for DEAD_CODE_STRIPPING and set the setting to NO.

This is still a workaround, though: let's hope a future Xcode version fixes this terrible bug.

Thank you very much @ydnar! See also https://twitter.com/rr/status/1190390966860935168

I'm leaving this issue open until the Xcode bug is fixed.

I could not reproduce the crash with Xcode 11.3 on an iOS simulator. But the two Swift bugs SR-11643 and SR-11564 are not marked as solved. Things are moving.

Workaround 2 didn't work for me.

I had to use the DEAD_CODE_STRIPPING workaround.

Tried on both real device (iOS 13.2.3) and sim (iOS 13.2.2). Brand new project with deployment target 13.2. Added GRDB via Swift Packages manager (is this what you call "Do not embed"?).

If it is of any use - I'm not using a struct, but a class, that inherits from Record, implements the enum Columns: String, ColumnExpression and overrides func encode(to container: inout PersistenceContainer).

I've checked this in Xcode 11.3 and it's fixed.

https://developer.apple.com/documentation/xcode_release_notes/xcode_11_3_release_notes

Swift Packages

Resolved Issues

  • You can now submit iOS, tvOS, or watchOS apps with a Swift Package that builds a dynamic library. (55564324) (FB7303066)

Thank you @AnthonyEgerton! We can finally close this issue 馃憤

Was this page helpful?
0 / 5 - 0 ratings