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

Conflict with Apple's Swift Charts #4897

Closed
mowafok764 opened this issue Sep 7, 2022 · 20 comments
Closed

Conflict with Apple's Swift Charts #4897

mowafok764 opened this issue Sep 7, 2022 · 20 comments
Assignees
Milestone

Comments

@mowafok764
Copy link

mowafok764 commented Sep 7, 2022

Is anyone else having issues while doing
import Charts
in SwiftUI ? It am trying to use Apple's Swift Charts (iOS 16 only) but it can't compile, I presume because the import statement is interpreted as targeting this library and not Apple's Swift Charts as I want to.

Any fix, workaround or way to specify better what to import is welcomed, haven't found any other solution than nuking this library from my project, however I would need it for users with iOS 15 or less.

What did you do?

Tried to use Apple's Swift Charts in some SwiftUI view in my app that uses this Github repo (https://github.com/danielgindi/Charts) in other places of the app, installed via cocoa pods.

I naturally do
import Charts
to import Apple's library, however it seems the compiler does not understands it that way as I can not use Swift Charts's charts in my SwiftUI struct view.

What did you expect to happen?

I expected this Chats library to not interfere.

What happened instead?

I seem to be unable to use Swift Charts because of this library

@xjki
Copy link

xjki commented Sep 8, 2022

This is because module name collision - this library uses the same module name that is used by new Swift Charts framework (available since iOS 16.0, mac OS 13.0).

Workaround:

  • fork repo
  • add s.module_name = 'DGCharts' to podspec in your repo
  • in the Podfile specify your fork
  • replace your import Charts statements with import DGCharts

To resolve this issue:

  • repo owner should decide on module prefix (I used DGCharts as reference to Daniel Gindi as repo owner)
  • change podspec, library name (maybe), and import statements in library (tests) accordingly

@waterskier2007
Copy link

related to #4845

yapwr added a commit to yapwr/Charts that referenced this issue Oct 20, 2022
Nikolas-LFDesigns added a commit to AURA-Devices/Charts that referenced this issue Oct 29, 2022
As per temporary solution proposed [here](ChartsOrg#4897 (comment)) we rename a module on pod spec to distinguish from recently-introduced [Swift Charts](https://developer.apple.com/documentation/charts) library. The hack provides a way to support both libraries on the main project and opens the path to step-by-step migration to the latter.
Nikolas-LFDesigns added a commit to AURA-Devices/Charts that referenced this issue Oct 29, 2022
As per temporary solution proposed [here](ChartsOrg#4897 (comment)) we rename a module on pod spec to distinguish from recently-introduced [Swift Charts](https://developer.apple.com/documentation/charts) library. The hack provides a way to support both libraries on the main project and opens the path to step-by-step migration to the latter.
@JanC
Copy link

JanC commented Jan 4, 2023

hey,
I'm having the same issue when using SPM. Is there a similar workaround for SPM?

@bentumbler
Copy link

bentumbler commented Feb 14, 2023

I modified Package.swift as below and compiled successfully by changing the import to DG Charts.

If I then add Import Charts to pull in the Swift charts I get a conflict elsewhere with the following message.
'PieChartDataEntry' is ambiguous for type lookup in this context

Any ideas what I can do?

// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

let package = Package(
    name: "DGCharts",
    platforms: [
          .iOS(.v12),
          .tvOS(.v12),
          .macOS(.v10_12),
    ],
    products: [
        .library(
            name: "DGCharts",
            targets: ["DGCharts"]),
        .library(
            name: "ChartsDynamic",
            type: .dynamic,
            targets: ["DGCharts"])
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0")
    ],
    targets: [
        .target(
            name: "DGCharts",
            dependencies: [.product(name: "Algorithms", package: "swift-algorithms")],
            path: "Source/Charts"
        )
    ],
    swiftLanguageVersions: [.v5]
)

@bentumbler
Copy link

ok, it was simple.
It needs to be called explicitly with DGCharts.PieChartDataEntry

@liuxuan30
Copy link
Member

@pmairoldi @danielgindi @jjatie shall we change the name to DG-iOS-Charts or similar to address the naming issue officially ? just decide an official name so we can continue?

@pmairoldi
Copy link
Collaborator

I think that DGCharts would be the most appropriate. Back to the old Objc way of meaning :p. I think we should make this a major release though.

@liuxuan30
Copy link
Member

I think that DGCharts would be the most appropriate. Back to the old Objc way of meaning :p. I think we should make this a major release though.

+1. Let's do it, if no body objects, like after a month?

@alextudge
Copy link

This would be very useful 🙏

@waterskier2007
Copy link

waterskier2007 commented Feb 21, 2023

Why wait a month? It's been months already since Apple's native Charts library has been released.

No one's going to object. On the contrary, people have been clamoring for this for a while.

@pmairoldi
Copy link
Collaborator

It might not take a month but we are giving ourselves time since we don’t do this full time. There is more to it than just renaming. We have to update all the docs in all languages, make sure the sample projects still all work, and maybe contact the people who made tutorials we link to in our readme to update their articles.

@waterskier2007
Copy link

That's a very fair point. Looking forward to the new release!

@liuxuan30
Copy link
Member

sorry. I already saw #5009 working on this.

@liuxuan30
Copy link
Member

liuxuan30 commented Mar 2, 2023

I think your #5009 is on the right rack but the name can't be UI prefixed. Let's rename to DGCharts and I'm willing to make #5009 merged as my 1st priority. and thanks @waterskier2007 for your effort!

@liuxuan30 liuxuan30 self-assigned this Mar 2, 2023
@waterskier2007
Copy link

I updated #5009

@pmairoldi pmairoldi modified the milestones: Future, 5.0.0 Mar 11, 2023
@JanC
Copy link

JanC commented Mar 14, 2023

I believe this could also be temporarily solved using the Swift 5.7 module alias feature

https://github.com/apple/swift-evolution/blob/main/proposals/0339-module-aliasing-for-disambiguation.md

@pmairoldi
Copy link
Collaborator

This is what I proposed to solve this problem a while ago but issues keep coming up so we are going to change the name.

@pmairoldi
Copy link
Collaborator

I haven’t pushed it yet but I’ve basically finished the renaming. I just need to validate that all build tools keep working.

@waterskier2007
Copy link

I believe this could also be temporarily solved using the Swift 5.7 module alias feature

https://github.com/apple/swift-evolution/blob/main/proposals/0339-module-aliasing-for-disambiguation.md

Yeah that could help on some projects, however all of the times I looked in to it, it really appears that Xcode doesn't have great support for module aliasing.

@pmairoldi
Copy link
Collaborator

Closed by #5027

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

8 participants