Created
April 18, 2018 07:55
-
-
Save artemnovichkov/7b9fe0497606b2317a15dde73f12f081 to your computer and use it in GitHub Desktop.
Code example for the article "Swift, Plist and Two Smoking Scripts" https://medium.com/rosberryapps/swift-plist-and-two-smoking-scripts-94bb54cbeded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// Get project URL | |
guard let projectDirRawValue = getenv("PROJECT_DIR"), | |
let projectDirectoryPath = String(utf8String: projectDirRawValue) else { | |
exit(1) | |
} | |
let projectURL = URL(fileURLWithPath: projectDirectoryPath) | |
// Get Info.plist path | |
guard let productSettingsPathRawValue = getenv("PRODUCT_SETTINGS_PATH"), | |
let productSettingsPath = String(utf8String: productSettingsPathRawValue) else { | |
exit(1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard let enumerator = FileManager.default.enumerator(at: projectURL, includingPropertiesForKeys: nil) else { | |
exit(1) | |
} | |
var swiftFileURLs = enumerator.allObjects | |
.compactMap { $0 as? URL } | |
.filter { $0.pathExtension == "swift" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keys: [String] = [] | |
for url in swiftFileURLs { | |
let contents = try String(contentsOf: url, encoding: .utf8) | |
for (pattern, key) in patterns { | |
if contents.contains(pattern) { | |
keys.append(key) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard let productSettings = NSDictionary(contentsOfFile: productSettingsPath) else { | |
exit(1) | |
} | |
for key in keys { | |
guard let value = productSettings[key] as? String else { | |
// Missing key | |
exit(1) | |
} | |
if value.isEmpty { | |
// Empty description | |
exit(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment