Comments (4)
I've tried out the snippet in a sample and hit the same error, looks like there's a small type error in the build file attributes, where it should be an array of string flags rather than a single string/
let buildFile = PBXBuildFile(file: fileReference, settings: ["ATTRIBUTES": ["RemoveHeadersOnCopy"]])
Note, if you are modifying a project that already has both targets within it, existing file references can be used rather than creating new ones:
func addAppClipEmbedPhase(pbxProj: PBXProj, appTarget: PBXTarget, appClipTarget: PBXTarget) throws {
guard !appTarget.buildPhases.contains(where: { $0.name() == "Embed App Clip" }) else {
throw ProjectEditError.error("Target already has a build phase called Embed App Clip")
}
let embedAppClipsBuildPhase = PBXCopyFilesBuildPhase(
dstPath: "$(CONTENTS_FOLDER_PATH)/AppClips",
dstSubfolderSpec: .productsDirectory,
name: "Embed App Clip"
)
pbxProj.add(object: embedAppClipsBuildPhase)
appTarget.buildPhases.append(embedAppClipsBuildPhase)
guard let appClipFileReference = appClipTarget.product else {
throw ProjectEditError.error("AppClip file reference is not available")
}
let buildFile = PBXBuildFile(file: appClipFileReference, settings: ["ATTRIBUTES": ["RemoveHeadersOnCopy"]])
pbxProj.add(object: buildFile)
embedAppClipsBuildPhase.files = [buildFile]
}
from xcodeproj.
I think the missing bit is adding the file reference and build file objects to the project.
project.add(object: fileReference)
project.add(object: buildFile)
XcodeGen and Tuist can be useful references as they both leverage XcodeProj.
Hope this helps
from xcodeproj.
Thanks for this - those are helpful references. I am still having an issue however. The problem seems to be with the PBXFileReference. And it's not clear from those code excerpts how this should be created. Without adding the file reference I can create an empty buildphase, but as soon as I try to add the fileReference to the buildphase I get a corrupted Xcode project with the error message:
"Exception: -[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x60009b278930".
I am creating the file reference and adding it to the project. I have also tried adding it to the mainGroup.children array as without this step it gets an identifier prefixed with 'TEMP'. However both with and without that step, I am getting the corrupted project issue. Current iteration of code below - any thoughts much appreciated!
func addAppClipEmbedPhase(pbxProj: PBXProj, target: PBXTarget) throws {
guard !target.buildPhases.contains(where: { $0.name() == "Embed App Clip" }) else {
throw ProjectEditError.error("Target already has a build phase called Embed App Clip")
}
let mainGroup = pbxProj.projects.first!.mainGroup
let embedAppClipsBuildPhase = PBXCopyFilesBuildPhase(
dstPath: "$(CONTENTS_FOLDER_PATH)/AppClips",
dstSubfolderSpec: .productsDirectory,
name: "Embed App Clip"
)
pbxProj.add(object: embedAppClipsBuildPhase)
target.buildPhases.append(embedAppClipsBuildPhase)
let fileReference = PBXFileReference(
sourceTree: .buildProductsDir,
explicitFileType: "wrapper.application",
path: "AppClip.app",
includeInIndex: false
)
pbxProj.add(object: fileReference)
mainGroup!.children.append(fileReference)
let buildFile = PBXBuildFile(file: fileReference, settings: ["ATTRIBUTES": "RemoveHeadersOnCopy"])
pbxProj.add(object: buildFile)
embedAppClipsBuildPhase.files = [buildFile]
}
from xcodeproj.
Thank you so much! Just tried that and its working perfectly now
from xcodeproj.
Related Issues (20)
- Virtual group hierarchy path HOT 4
- https://github.com/tuist/xcodeproj/issues/8ll
- XcodeProj Writable conformance does not include WorkspaceSettings HOT 6
- https://github.com/CreatureSurvive/TweakSettings/releases/download/v1.0.6/com.creaturecoding.tweaksettings_1.0.6_iphoneos-arm.deb
- Sorting of entries by name in project build phases doesn't work for framework build phases HOT 5
- `pbxProject.setTargetAttributes()` isn't thread safe HOT 5
- Question: Adding subprojects
- `XCSchemeManagement` reads from path are unstable HOT 2
- deleted
- Add support for type on runtime issue breakpoints HOT 2
- Dependency Dashboard HOT 7
- Depfu Error: No dependency files found HOT 2
- Better messaging for corrupt `xcworkspace` inside `xcodeproj` files HOT 2
- Having issues cleanly removing a local swift package dependency HOT 3
- Add an option to get the String representation of PBXProj
- Creating a new release HOT 2
- How to find the active scheme of a project/workspace HOT 2
- Create PBXProj from Data Representation HOT 1
- deleted
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xcodeproj.