Adjusting framework settings to only be applied when embedding to avoid parsing crashes on Xcode 7.3
diff --git a/lib/pbxFile.js b/lib/pbxFile.js
index b226550..b178645 100644
--- a/lib/pbxFile.js
+++ b/lib/pbxFile.js
@@ -34,6 +34,7 @@
         'archive.ar': 'Frameworks',
         'compiled.mach-o.dylib': 'Frameworks',
         'wrapper.framework': 'Frameworks',
+        'embedded.framework': 'Embed Frameworks',
         'sourcecode.c.h': 'Resources',
         'sourcecode.c.objc': 'Sources',
         'sourcecode.swift': 'Sources'
@@ -93,7 +94,7 @@
     }
 }
 
-function detectGroup(fileRef) {
+function detectGroup(fileRef, opt) {
     var extension = path.extname(fileRef.basename).substring(1),
         filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
         groupName = GROUP_BY_FILETYPE[unquoted(filetype)];
@@ -102,6 +103,10 @@
         return 'Sources';
     }
 
+    if (opt.customFramework && opt.embed) {
+        return GROUP_BY_FILETYPE['embedded.framework'];
+    }
+
     if (!groupName) {
         return DEFAULT_GROUP;
     }
@@ -161,7 +166,7 @@
 
     this.basename = path.basename(filepath);
     this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath);
-    this.group = detectGroup(self);
+    this.group = detectGroup(self, opt);
 
     // for custom frameworks
     if (opt.customFramework == true) {
@@ -195,7 +200,7 @@
         this.settings.COMPILER_FLAGS = util.format('"%s"', opt.compilerFlags);
     }
 
-    if (opt.sign) {
+    if (opt.embed && opt.sign) {
       if (!this.settings)
           this.settings = {};
       if (!this.settings.ATTRIBUTES)
diff --git a/lib/pbxProject.js b/lib/pbxProject.js
index 77b4530..e76b499 100644
--- a/lib/pbxProject.js
+++ b/lib/pbxProject.js
@@ -261,6 +261,13 @@
 }
 
 pbxProject.prototype.addFramework = function(fpath, opt) {
+    var customFramework = opt && opt.customFramework == true;
+    var link = !opt || (opt.link == undefined || opt.link);    //defaults to true if not specified
+    var embed = opt && opt.embed;                              //defaults to false if not specified
+
+    if (opt) {
+      delete opt.embed;
+    }
 
     var file = new pbxFile(fpath, opt);
 
@@ -270,10 +277,6 @@
 
     if (this.hasFile(file.path)) return false;
 
-    var customFramework = opt && opt.customFramework == true;
-    var link = !opt || (opt.link == undefined || opt.link);    //defaults to true if not specified
-    var embed = opt && opt.embed;                              //defaults to false if not specified
-
     this.addToPbxBuildFileSection(file);        // PBXBuildFile
     this.addToPbxFileReferenceSection(file);    // PBXFileReference
     this.addToFrameworksPbxGroup(file);         // PBXGroup
@@ -286,7 +289,18 @@
         this.addToFrameworkSearchPaths(file);
 
         if (embed) {
-          this.addToPbxEmbedFrameworksBuildPhase(file); // PBXCopyFilesBuildPhase
+          opt.embed = embed;
+          var embeddedFile = new pbxFile(fpath, opt);
+
+          embeddedFile.uuid = this.generateUuid();
+          embeddedFile.fileRef = file.fileRef;
+
+          //keeping a separate PBXBuildFile entry for Embed Frameworks
+          this.addToPbxBuildFileSection(embeddedFile);        // PBXBuildFile
+
+          this.addToPbxEmbedFrameworksBuildPhase(embeddedFile); // PBXCopyFilesBuildPhase
+
+          return embeddedFile;
         }
     }
 
@@ -294,6 +308,12 @@
 }
 
 pbxProject.prototype.removeFramework = function(fpath, opt) {
+    var embed = opt && opt.embed;
+
+    if (opt) {
+      delete opt.embed;
+    }
+
     var file = new pbxFile(fpath, opt);
     file.target = opt ? opt.target : undefined;
 
@@ -301,12 +321,19 @@
     this.removeFromPbxFileReferenceSection(file);      // PBXFileReference
     this.removeFromFrameworksPbxGroup(file);           // PBXGroup
     this.removeFromPbxFrameworksBuildPhase(file);      // PBXFrameworksBuildPhase
-    this.removeFromPbxEmbedFrameworksBuildPhase(file); // PBXCopyFilesBuildPhase
 
     if (opt && opt.customFramework) {
         this.removeFromFrameworkSearchPaths(path.dirname(fpath));
     }
 
+    opt.embed = true;
+    var embeddedFile = new pbxFile(fpath, opt);
+
+    embeddedFile.fileRef = file.fileRef;
+
+    this.removeFromPbxBuildFileSection(embeddedFile);          // PBXBuildFile
+    this.removeFromPbxEmbedFrameworksBuildPhase(embeddedFile); // PBXCopyFilesBuildPhase
+
     return file;
 }
 
@@ -600,12 +627,13 @@
 pbxProject.prototype.removeFromPbxEmbedFrameworksBuildPhase = function (file) {
     var sources = this.pbxEmbedFrameworksBuildPhaseObj(file.target);
     if (sources) {
+        var files = [];
         for (i in sources.files) {
-            if (sources.files[i].comment == longComment(file)) {
-                sources.files.splice(i, 1);
-                break;
+            if (sources.files[i].comment != longComment(file)) {
+                files.push(sources.files[i]);
             }
         }
+        sources.files = files;
     }
 }
 
diff --git a/package.json b/package.json
index 58bcdda..1761a88 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "author": "Andrew Lunny <alunny@gmail.com>",
   "name": "xcode",
   "description": "parser for xcodeproj/project.pbxproj files",
-  "version": "0.8.3",
+  "version": "0.8.6",
   "main": "index.js",
   "repository": {
     "url": "https://github.com/alunny/node-xcode.git"
diff --git a/test/addFramework.js b/test/addFramework.js
index efae42e..d631bab 100644
--- a/test/addFramework.js
+++ b/test/addFramework.js
@@ -45,7 +45,6 @@
 exports.addFramework = {
     'should return a pbxFile': function (test) {
         var newFile = proj.addFramework('libsqlite3.dylib');
-        console.log(newFile);
 
         test.equal(newFile.constructor, pbxFile);
         test.done()
@@ -131,18 +130,6 @@
 
         test.done();
     },
-    'should add the PBXBuildFile object correctly /w signable frameworks': function (test) {
-        var newFile = proj.addFramework('libsqlite3.dylib', { sign: true }),
-            buildFileSection = proj.pbxBuildFileSection(),
-            buildFileEntry = buildFileSection[newFile.uuid];
-
-        test.equal(buildFileEntry.isa, 'PBXBuildFile');
-        test.equal(buildFileEntry.fileRef, newFile.fileRef);
-        test.equal(buildFileEntry.fileRef_comment, 'libsqlite3.dylib');
-        test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: [ 'CodeSignOnCopy' ] });
-
-        test.done();
-    },
     'should add to the Frameworks PBXGroup': function (test) {
         var newLength = proj.pbxGroupByName('Frameworks').children.length + 1,
             newFile = proj.addFramework('libsqlite3.dylib'),
@@ -229,4 +216,17 @@
         test.equal(frameworks.files.length, 0);
         test.done();
     },
+    'should add the PBXBuildFile object correctly /w signable frameworks': function (test) {
+        var newFile = proj.addFramework('/path/to/SomeSignable.framework', { customFramework: true, embed: true, sign: true }),
+            buildFileSection = proj.pbxBuildFileSection(),
+            buildFileEntry = buildFileSection[newFile.uuid];
+
+        test.equal(newFile.group, 'Embed Frameworks');
+        test.equal(buildFileEntry.isa, 'PBXBuildFile');
+        test.equal(buildFileEntry.fileRef, newFile.fileRef);
+        test.equal(buildFileEntry.fileRef_comment, 'SomeSignable.framework');
+        test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: [ 'CodeSignOnCopy' ] });
+
+        test.done();
+    },
 }