Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode Previews break immediately after adding this package as package dependency #9

Open
kemalcany opened this issue Dec 12, 2024 · 2 comments

Comments

@kemalcany
Copy link

Hi PS Team! Thank you for this new repo, it's an exciting start!

There is however a problem with this package dependency in a way that I couldn't figure out but it is very easy to reproduce:

  • If you start a new Swift project the Xcode preview work as normal, with a HelloWorld view
  • If you add the powersync-swift dependency (with the details below, from main branch) the previews break. The bug report is too complicated
  • If you remove the dependency then the Previews are back. 🤷🏽‍♂️

Please check! Thank you!

import PackageDescription
let packageName = "PowerSync"

let package = Package(
    name: packageName,
    platforms: [
        .iOS(.v13),
        .macOS(.v10_13)
    ],
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: packageName,
            targets: ["PowerSync"]),
    ],
    dependencies: [
        .package(url: "https://github.com/powersync-ja/powersync-kotlin.git", exact: "1.0.0-BETA11.0"),
        .package(url: "https://github.com/powersync-ja/powersync-sqlite-core-swift.git", "0.3.1"..<"0.4.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: packageName,
            dependencies: [
                .product(name: "PowerSyncKotlin", package: "powersync-kotlin"),
                .product(name: "PowerSyncSQLiteCore", package: "powersync-sqlite-core-swift")
            ]),
        .testTarget(
            name: "PowerSyncTests",
            dependencies: ["PowerSync"]
        ),
    ]
)
@DominicGBauer
Copy link
Contributor

Hi @kemalcany. Thanks for reporting this issue. It appears to be an issue with XCode as noted here https://forums.developer.apple.com/forums/thread/763907.

The workaround for now is to go to Editor > Canvas > Use Legacy Previews Execution
image

That will load the preview.

@kemalcany
Copy link
Author

Thanks @DominicGBauer ! It's true that the previews started working when set as Legacy Execution. Thanks for the tip.

Also, in case this might be useful for anyone in the future, if you are using PS data in your previews and ps is passing as @Environment you might want to open it first and access data as follows:

(although as long as you dont connect, it wont be live):

#Preview {
    let mockPowerSync = PowerSyncService()
    mockPowerSync.openDb()
    return SeasonsPage().environment(mockPowerSync)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants