Created
October 26, 2016 13:09
-
-
Save nolanw/5ec34a59a3a56e6fe45e5fa3ab53f38d to your computer and use it in GitHub Desktop.
Xcode project file plist linter
This file contains hidden or 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
#!/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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swift version of http://stackoverflow.com/a/10560271/1063051
Made after running into CocoaPods/CocoaPods#5311 (real unhelpful error btw)