@@ -669,27 +669,35 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
669669 if ( ! groupKey ) {
670670 return ;
671671 }
672+
673+ this . removePbxGroupByKey ( groupKey , path ) ;
674+ }
675+
676+ pbxProject . prototype . removePbxGroupByKey = function ( groupKey , path ) {
672677 var group = this . getPBXGroupByKey ( groupKey ) || this . getPBXVariantGroupByKey ( groupKey )
678+
679+ if ( ! group ) {
680+ return ;
681+ }
673682
674683 path = path || "" ;
675-
676684 var children = group . children ;
677685
678686 for ( i in children ) {
679687 var file = new pbxFile ( $path . join ( path , children [ i ] . comment ) ) ;
680688 file . fileRef = children [ i ] . value ;
681689 file . uuid = file . fileRef ;
682- this . removePbxGroup ( children [ i ] . comment , $path . join ( path , children [ i ] . comment ) ) ;
683- this . removeFromPbxFileReferenceSection ( file ) ;
690+ this . removePbxGroupByKey ( children [ i ] . value , $path . join ( path , children [ i ] . comment ) ) ;
691+ this . removeFromPbxFileReferenceSectionByUuid ( children [ i ] . value ) ;
684692 this . removeFromPbxBuildFileSection ( file ) ;
685693 this . removeFromPbxSourcesBuildPhase ( file ) ;
686694 }
687695
688696 var mainGroup = this . findMainPbxGroup ( ) ;
689697 if ( mainGroup ) {
690- var mainGroupChildren = this . findMainPbxGroup ( ) . children , i ;
698+ var mainGroupChildren = mainGroup . children , i ;
691699 for ( i in mainGroupChildren ) {
692- if ( mainGroupChildren [ i ] . comment == groupName ) {
700+ if ( mainGroupChildren [ i ] . value == groupKey ) {
693701 mainGroupChildren . splice ( i , 1 ) ;
694702 }
695703 }
@@ -702,15 +710,7 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
702710 section = this . hash . project . objects [ 'PBXGroup' ] ;
703711 }
704712
705- for ( key in section ) {
706- // only look for comments
707- if ( ! COMMENT_KEY . test ( key ) ) continue ;
708-
709- if ( section [ key ] == groupName ) {
710- itemKey = key . split ( COMMENT_KEY ) [ 0 ] ;
711- delete section [ itemKey ] ;
712- }
713- }
713+ removeItemAndCommentFromSectionByUuid ( section , groupKey ) ;
714714}
715715
716716pbxProject . prototype . addToPbxProjectSection = function ( target ) {
@@ -759,6 +759,12 @@ pbxProject.prototype.removeFromPbxFileReferenceSection = function(file) {
759759 return file ;
760760}
761761
762+ pbxProject . prototype . removeFromPbxFileReferenceSectionByUuid = function ( fileUuid ) {
763+ var section = this . pbxFileReferenceSection ( ) ;
764+
765+ removeItemAndCommentFromSectionByUuid ( section , fileUuid ) ;
766+ }
767+
762768pbxProject . prototype . addToXcVersionGroupSection = function ( file ) {
763769 if ( ! file . models || ! file . currentModel ) {
764770 throw new Error ( "Cannot create a XCVersionGroup section from not a data model document file" ) ;
0 commit comments