Skip to content

Commit ec3f739

Browse files
committed
Added "updateProductName" method.
1 parent d621e02 commit ec3f739

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/pbxProject.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ pbxProject.prototype.pbxBuildFileSection = function () {
298298
return this.hash.project.objects['PBXBuildFile'];
299299
}
300300

301+
pbxProject.prototype.pbxXCBuildConfigurationSection = function () {
302+
return this.hash.project.objects['XCBuildConfiguration'];
303+
}
304+
301305
pbxProject.prototype.pbxFileReferenceSection = function () {
302306
return this.hash.project.objects['PBXFileReference'];
303307
}
@@ -348,6 +352,24 @@ pbxProject.prototype.buildPhaseObject = function (name, group) {
348352
return null;
349353
}
350354

355+
pbxProject.prototype.updateProductName = function(name) {
356+
var config = this.pbxXCBuildConfigurationSection();
357+
propReplace(config, 'PRODUCT_NAME', '"' + name + '"');
358+
};
359+
360+
// helper recursive prop search+replace
361+
function propReplace(obj, prop, value) {
362+
for (var p in obj) {
363+
if (obj.hasOwnProperty(p)) {
364+
if (typeof obj[p] == 'object') {
365+
propReplace(obj[p], prop, value);
366+
} else if (p == prop) {
367+
obj[p] = value;
368+
}
369+
}
370+
}
371+
}
372+
351373
// helper object creation functions
352374
function pbxBuildFileObj(file) {
353375
var obj = Object.create(null);

0 commit comments

Comments
 (0)