This is a library I wrote that parses Xcode .pbxproj project files. While it doesn’t write the files out exactly the way Xcode itself does (i.e. there are some indentation differences), it should come pretty close.
XcodeKit is an Objective-C port of Ray Yamamoto Hilton’s wonderful xcoder Ruby gem. Some portions are also borrowed from the CocoaPods Xcodeproj gem. Many thanks!