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.
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:
I noticed some issues:
1. The uuids does not seems to be generated correctly
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
objectsarray.However, that's not enough to configure the project:
PBXProjectneeds to be updated with an array ofpackageReferencesXCLocalSwiftPackageReferencePBXBuildFileneeds to have an entry for each package that needs to be built.productRefhas to point to the XCSwiftPackageProductDependencyPBXFrameworksBuildPhasePBXFrameworkBuildPhaseabove needs to be added to a PBXNativeTarget'sbuildPhasesectionPBXProjectfileHow 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
getObjectmethod but it requires auuid. There is noremoveObjecteither.