Skip to content

SwiftPackage elements not working correctly #31

@cipolleschi

Description

@cipolleschi

I was playing with the package to see how can I use it to add local SwiftPM packages to my project.

The code is something like this:

  const project = XcodeProject.open(xcodeProjectPath);
  // React
  const reactNativePackage = XCLocalSwiftPackageReference.create(project, {
    relativePath: path.relative(appIosPath, reactNativePath),
  });

  const reactNativeProductDependency = XCSwiftPackageProductDependency.create(project, {
    productName: 'React',
  });

I noticed some issues:

1. The uuids does not seems to be generated correctly

console.log(reactNativePackage.uuid)
// XX37FEFE0D07D0B50AB6ACXX

console.log(reactNativeProductDependency.uuid)
// XXD04A0B59BD7509D3A4FDXX

The XX at the beginning and end of the uuids are not Hex values, so they can't be correct

2. Elements are added to the project but they are not added to the PBXProject

The create method correctly adds the packages and the product dependencies into the objects array.
However, that's not enough to configure the project:

  • the PBXProject needs to be updated with an array of packageReferences
    • The package references are the uuids of the XCLocalSwiftPackageReference
  • the PBXBuildFile needs to have an entry for each package that needs to be built.
    • The productRef has to point to the XCSwiftPackageProductDependency
    • The buildfile id needs to be added to a PBXFrameworksBuildPhase
    • The id of the PBXFrameworkBuildPhase above needs to be added to a PBXNativeTarget's buildPhase section
    • The native target needs to be part of the PBXProject file

How can we do this properly?

3. Removing old Swift Package References

I couldn't find a way to remove old package references. When reading the project, we might not know the ids in advance and we would have to iterate to the objects or filter them out somehow.

I saw the getObject method but it requires a uuid. There is no removeObject either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions