Skip to content

Commit

Permalink
Add autoCreateSchemes attribute to WorkspaceSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Piñera committed Apr 2, 2019
1 parent 86b5dd4 commit a06299b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Fixtures/WorkspaceSettings/Default.xcsettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http:https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
<true/>
</dict>
</plist>
19 changes: 16 additions & 3 deletions Sources/xcodeproj/Project/WorkspaceSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,26 @@ public class WorkspaceSettings: Codable, Equatable, Writable {
/// Workspace build system.
public var buildSystem: BuildSystem

/// When true, Xcode auto-creates schemes in the project.
public var autoCreateSchemes: Bool?

/// Decodable coding keys.
///
/// - buildSystem: Build system.
enum CodingKeys: String, CodingKey {
case buildSystem = "BuildSystemType"
case autoCreateSchemes = "IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded"
}

/// Initializes the settings with its attributes.
///
/// - Parameter buildSystem: Workspace build system.
init(buildSystem: BuildSystem = .new) {
/// - Parameters:
/// - buildSystem: Workspace build system.
/// - autoCreateSchemes: When true, Xcode auto-creates schemes in the project.
init(buildSystem: BuildSystem = .new,
autoCreateSchemes: Bool? = nil) {
self.buildSystem = buildSystem
self.autoCreateSchemes = autoCreateSchemes
}

/// Initializes the settings decoding the values from the plist representation.
Expand All @@ -45,6 +53,7 @@ public class WorkspaceSettings: Codable, Equatable, Writable {
} else {
buildSystem = .new
}
autoCreateSchemes = try container.decodeIfPresent(.autoCreateSchemes)
}

/// Encodes the settings into the given encoder.
Expand All @@ -56,6 +65,9 @@ public class WorkspaceSettings: Codable, Equatable, Writable {
if buildSystem == .original {
try container.encode(buildSystem.rawValue, forKey: .buildSystem)
}
if let autoCreateSchemes = autoCreateSchemes {
try container.encode(autoCreateSchemes, forKey: .autoCreateSchemes)
}
}

/// Initializes the settings reading the values from the WorkspaceSettings.xcsettings file.
Expand All @@ -79,7 +91,8 @@ public class WorkspaceSettings: Codable, Equatable, Writable {
/// - rhs: Second instance to be compared.
/// - Returns: True if the two instances are the same.
public static func == (lhs: WorkspaceSettings, rhs: WorkspaceSettings) -> Bool {
return lhs.buildSystem == rhs.buildSystem
return lhs.buildSystem == rhs.buildSystem &&
lhs.autoCreateSchemes == rhs.autoCreateSchemes
}

/// Writes the workspace settings.
Expand Down
6 changes: 6 additions & 0 deletions Tests/xcodeprojTests/Project/WorkspaceSettingsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ final class WorkspaceSettingsTests: XCTestCase {
XCTAssertEqual(got.buildSystem, .new)
}

func test_init_when_autoCreateSchemes_is_true() throws {
let path = fixturesPath() + "WorkspaceSettings/Default.xcsettings"
let got = try WorkspaceSettings.at(path: path)
XCTAssertTrue(got.autoCreateSchemes == true)
}

func test_equals() {
let lhs = WorkspaceSettings(buildSystem: .new)
let rhs = WorkspaceSettings(buildSystem: .original)
Expand Down

0 comments on commit a06299b

Please sign in to comment.