diff --git a/.gitignore b/.gitignore index 2c22487..dc51c07 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ playground.xcworkspace # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. # Packages/ .build/ +.swiftpm # CocoaPods # diff --git a/Sources/XcodeProject/Objects+Extensions/PBXGroup+FolderSync.swift b/Sources/XcodeProject/Objects+Extensions/PBXGroup+FolderSync.swift index 95d7911..9492016 100644 --- a/Sources/XcodeProject/Objects+Extensions/PBXGroup+FolderSync.swift +++ b/Sources/XcodeProject/Objects+Extensions/PBXGroup+FolderSync.swift @@ -42,6 +42,7 @@ public extension PBXGroup { func sync(recursive: Bool, target: PBXTarget? = nil) { let target = target ?? parentProject?.targets.first removeDuplicateFiles(recursive: recursive) + removeDuplicateFilesByPath(recursive: recursive) addMissingFiles(recursive: recursive, target: target) removeMissingFiles(recursive: recursive) } @@ -65,6 +66,27 @@ public extension PBXGroup { } } + private func removeDuplicateFilesByPath(recursive: Bool) { + var itemsByPath: [String: [PBXReference]] = [:] + for i in 0.. 1 } + duplicatePathItems.forEach { (path, references) in + references.forEach { reference in + if reference.buildFiles.isEmpty { + remove(child: reference) + } + } + } + } + private func removeMissingFiles(recursive: Bool) { var newChildren: [PBXReference] = [] children.forEach { @@ -103,6 +125,7 @@ public extension PBXGroup { private func addMissingFiles(recursive: Bool, target: PBXTarget?) { guard let url = self.url else { return } + let childPathItems: [(String, PBXReference)] = children.compactMap { guard let childURL = $0.url else { return nil } return (childURL.path, $0) diff --git a/Sources/XcodeProject/Objects/PBXGlobalID.swift b/Sources/XcodeProject/Objects/PBXGlobalID.swift index 6410a4f..95b06ca 100644 --- a/Sources/XcodeProject/Objects/PBXGlobalID.swift +++ b/Sources/XcodeProject/Objects/PBXGlobalID.swift @@ -7,7 +7,10 @@ import Foundation -public struct PBXGlobalID: RawRepresentable { +public struct PBXGlobalID: RawRepresentable, CustomStringConvertible, CustomDebugStringConvertible { + public var description: String { return rawValue } + public var debugDescription: String { return rawValue } + public let rawValue: String public init(rawValue: String) {