Files
XcodeGen/Sources/ProjectSpec/ProjectExtensions.swift
T
2017-08-25 15:31:50 +02:00

72 lines
1.6 KiB
Swift

//
// ProjectExtensions.swift
// XcodeGen
//
// Created by Yonas Kolb on 19/7/17.
//
//
import Foundation
import xcodeproj
import PathKit
extension Array where Element: Referenceable {
public var referenceList: [String] {
return map { $0.reference }
}
public var referenceSet: Set<String> {
return Set(referenceList)
}
}
extension Dictionary where Key == String, Value: Any {
public func merged(_ dictionary: [Key: Value]) -> [Key: Value] {
var mergedDictionary = self
mergedDictionary.merge(dictionary)
return mergedDictionary
}
public mutating func merge(_ dictionary: [Key: Value]) {
for (key, value) in dictionary {
self[key] = value
}
}
public func equals(_ dictionary: BuildSettings) -> Bool {
return NSDictionary(dictionary: self).isEqual(to: dictionary)
}
}
public func +=(lhs: inout BuildSettings, rhs: BuildSettings?) {
guard let rhs = rhs else { return }
lhs.merge(rhs)
}
extension PBXProductType {
init?(string: String) {
if let type = PBXProductType(rawValue: string) {
self = type
} else if let type = PBXProductType(rawValue: "com.apple.product-type.\(string)") {
self = type
} else {
return nil
}
}
public var isExtension: Bool {
return fileExtension == "appex"
}
public var isApp: Bool {
return fileExtension == "app"
}
public var name: String {
return rawValue.replacingOccurrences(of: "com.apple.product-type.", with: "")
}
}