Skip to content

Instantly share code, notes, and snippets.

@nolanw
Created October 26, 2016 13:09
Show Gist options
  • Save nolanw/5ec34a59a3a56e6fe45e5fa3ab53f38d to your computer and use it in GitHub Desktop.
Save nolanw/5ec34a59a3a56e6fe45e5fa3ab53f38d to your computer and use it in GitHub Desktop.
Xcode project file plist linter
#!/usr/bin/env swift
// Swift 3.0
import Foundation
func main() -> Int32 {
if CommandLine.arguments.count < 2 {
print("")
print("Usage: \(CommandLine.arguments[0]) (path_to_pbxproj | path_to_xcodeproj)")
print("")
print(" Tries to deserialize a pbxproj and report any errors in doing so.")
print(" Can be helpful after an attempted git merge.")
print("")
return 1
}
let inputPath = CommandLine.arguments[1]
var url = URL(fileURLWithPath: inputPath)
if url.pathExtension == "xcodeproj" {
url = url.appendingPathComponent("project.pbxproj")
}
guard let stream = InputStream(url: url) else { fatalError("Could not open \(url)") }
stream.open()
do {
try PropertyListSerialization.propertyList(with: stream, options: [], format: nil)
return 0
} catch let error as NSError {
if
let underlyingError = error.userInfo["kCFPropertyListOldStyleParsingError"] as? NSError,
let debugDescription = underlyingError.userInfo["NSDebugDescription"] as? String
{
print(debugDescription)
}
else {
print(error)
}
return 1
}
}
exit(main())
@nolanw
Copy link
Author

nolanw commented Oct 26, 2016

Swift version of http://stackoverflow.com/a/10560271/1063051

Made after running into CocoaPods/CocoaPods#5311 (real unhelpful error btw)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment