RedMadRobot / figma-export

Command line utility to export colors, typography, icons and images from Figma to Xcode / Android Studio project
MIT License
726 stars 114 forks source link

Support SwiftPM: Handle Swift package asset catalogs #73

Closed JonLz closed 3 years ago

JonLz commented 3 years ago

I am integrating the figma exported color palette into a swift package. Currently, there is no way to support this as the generated extensions result in an runtime error due to how the bundle is accessed. This code fails when used in a Swift package:

let bundleProvider = """

private class BundleProvider {
    static let bundle = Bundle(for: BundleProvider.self)
}

"""

Per the Apple docs we want to do this:

Important

Always use Bundle.module when you access resources. A package shouldn’t make assumptions about the exact location of a resource.

This PR adds a flag for this use case and modifies the bundle provider as per the note. Tested and working with a SwiftPM repo.

subdan commented 3 years ago

Cool! Thanks for the PR. I will review it tomorrow.