22 ms·
The joys of creating Xcode project files
- db48x 6y agoIt would be pretty hard to do all of that on purpose, let alone by accident, or by gradual accretion of new features. They must have worked really hard on that mess.
- ajconway 6y agoSo it’s just a legacy file format that (as reflected in the article) has likely evolved from an internal object representation in the early days of macOS X (maybe earlier?). Apple has been working on the tooling for the past several years. They improved the editor performance, created a new build system (llb), made a native dependency manager (swiftpm). For third-party tools they have released an LSP extension (hopefully they’ll end up using it internally in Xcode).
- rmorey 6y ago> maybe earlier? Yes, XCode originates from NeXTSTEP’s Project Builder: https://en.wikipedia.org/wiki/Project_Builder https://en.wikipedia.org/wiki/Project_Builder
- agsnu 6y agoOnly in spirit. NeXTStep's ProjectBuilder was GNU Make based, and IIRC it directly edited Makefiles (restricted subset of make - and you weren't supposed to touch them by hand) and also had a PB.project file that contained some limited metadata. What became Xcode started out life as "Project Builder" (with a space), which was where the pbxproj file format was introduced. This debuted with Mac OS X (possibly circa DP4?) and was a ground-up rewrite - new UI, new project format, new build system (originally it used Jam, a little-known build system created by Perforce, before switching to something custom... IIRC it would generate an ephemeral Jamfile at build time). For a while both could be installed on the same system - you needed ye olde NeXT ProjectBuilder for WebObjects 4.5 projects, and it was known as ProjectBuilderWO on Mac OS X for a while as a result.
- eddieh 6y agoThis is correct. The format was really nice during the NeXTStep era. It was an simple ASCII plist file called PB.project. It could be edited by a human. When Apple started "improving" stuff it turned into the SomeProject.pbproj/project.pbxproj file and was not editable by a human. This file would later become SomeProject.xcode/project.pbxproj and then SomeProject.xcodeproj/project.pbxproj all the while getting worse and worse and less editable and less readable/understandable. Here is the entire project file (PB.project) for IORegistryExplorer from Mac OS X 10.0 { APPCLASS = NSApplication; DYNAMIC_CODE_GEN = YES; English_RESOURCES = {}; FILESTABLE = { CLASSES = ( RExplorer.m, "RExplorer-OutlineDelegate.m", "RExplorer-BrowserDelegate.m", CustomOutlineView.m, RSearch.m, RBool.m ); English_INTERFACES = (IORegistryExplorer.nib); FRAMEWORKS = (AppKit.framework, Foundation.framework, IOKit.framework, System.framework); FRAMEWORKSEARCH = (); H_FILES = ( RExplorer.h, CustomOutlineView.h, "RExplorer-OutlineDelegate.h", "RExplorer-BrowserDelegate.h", RSearch.h, RBool.h ); IMAGES = (IORE.tiff); INTERFACES = (); OTHER_LINKED = (IORegistryExplorer_main.m); OTHER_RESOURCES = (IORE.icns); OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, CustomInfo.plist); SUBPROJECTS = (); }; LANGUAGE = English; MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; NEXTSTEP_APPICON = IORE.tiff; NEXTSTEP_BUILDTOOL = /bin/gnumake; NEXTSTEP_DOCUMENTEXTENSIONS = (); NEXTSTEP_INSTALLDIR = "$(SYSTEM_DEVELOPER_APPS_DIR)"; NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; NEXTSTEP_MAINNIB = IORegistryExplorer.nib; NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; PDO_UNIX_INSTALLDIR = /Applications; PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; PROJECTNAME = IORegistryExplorer; PROJECTTYPE = Application; PROJECTVERSION = 2.8; WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; WINDOWS_INSTALLDIR = /Applications; WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; WINDOWS_MAINNIB = "IORegistryExplorer-windows.nib"; WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; } Simple. Elegant. Usable.
- flohofwoe 6y agoThis is actually the one feature where CMake really shines, and big kudos to the CMake team for this: IDE project file generation never breaks when new versions of those IDEs are released (or at least regressions happen extremely rarely and are fixed promptly). This must be one of the most frustrating and unthankful tasks in the entire domain of programming.
- spacedcowboy 6y agocmake shudder No thanks. I am one whom cmake has tried. When it works, it works well. When it doesn't, it is utterly impenetrable. I actively avoid any GitHub projects that use cmake because it's just normally too painful to use, and it brings on an episode of PTS. Just writing this is causing my blood pressure to rise.
- tersers 6y agoHasn’t been updated in a while, but “Texts from Xcode” (https://www.textfromxcode.com/ https://www.textfromxcode.com/) has some fun collections of frustrations.
- deleted 6y ago[deleted]
- orf 6y ago> However being the maintainer of a build system means that sometimes people tell you things. Those things may be false or fabricated, of course, so the following is just speculation. I certainly have no proof for any of it. Anyhow it seems that a lot the fundamental code that is used to build macOS exists only in Xcode projects created ages ago. The authors of said projects have since left the company and nobody touches those projects for fear of breaking things. If true this would indicate that the Xcode development team has to keep those old versions working. No matter what.
- dalemyers 6y agoWhile I don't disagree that the pbxformat is awful, there are some reasons behind the design. Take the example of PBXBuildFile in the article. Here's a quote: > There is no other data in this object. Its only reason for existing, as far as I can tell, is to point to the actual PBXFileReference object which contains the filesystem path. Now, that statement is true most of the time. But not always. Let's say you have a file in two targets (targets ~= binaries). In one of those targets, you need to set a build flag, but not the other, how do you do it? Well, you set it on the PBXBuildFile, rather than the PBXFileReference. In otherwords, you can have 2 different PBXBuildFile's, with 2 different sets of flags, pointing at the same actual file on disk. Whether that's a good design or not is definitely up for debate, but I wanted to clarify that there are reasons behind everything. Going further: > Since everything has a unique ID, a reasonable expectation would be that a) it would be unique per object and b) you would use that ID to refer to the target. Neither of these are true. For example let's define a single build target, which in Xcode/CMake parlance is a PBXNativeTarget. Since plist has a native array type, the target's sources could be listed in an array of unique ids of the files. Instead the array contains a reference to a PBXSourcesBuildPhase object that has a few keys which are useless and always the same and an array of unique ids. Let's take a sub-statement here first: > Since everything has a unique ID, a reasonable expectation would be that a) it would be unique per object The author claims this is false, but I've never seen a case where this hasn't held up. Numerous libraries depend on this fact. > you would use that ID to refer to the target Also claimed as false, but you do. The argument the author makes talks about the build file stuff I mentioned above, so they may just be misunderstanding or have mis-spoken/written. Just to re-iterate, I'm not a fan of this format at all. I'm actually in the middle of converting a million line project to use XcodeGen just so I can get away from it. But everything does have a reason.
- xbar 6y agoIt is not necessary for bad software to remain bad. There may be a reason for some decisions, but it does not mean that such decisions must be permanent. Xcode 12 UX is an example where Apple seemed willing to invest. There may be reasons pbxformat is bad, but there is no reason Xcode 13 or 14 couldn't address them. After all, it's only software.
- _mlxl 6y agoXcode unironically made me try to change career from iOS developer to pen tester. I've spent way too much time in its guts and I think its left a little bit of taint on my soul. It is unfathomably bad. And Apple keep bolting stuff on to it (and the new stuff doesn't work - Canvas for SwiftUI previews for example). It's slow, broken in numerous ways, depends on file formats that aren't used anywhere outside of Apple and completely undocumented. It is such a painful tool to use.
- OnlyMortal 6y agoI’m with you. The original applications of Project Builder, Interface Builder and TextEdit were better because they were focused. Feature creep is never a good thing. It’d have been better to build tools for Swift in its own right, allowing those tools to integrate - probably by using distributed objects. But, it isn’t that way so such is life.
- azinman2 6y agoI strongly disagree. I don’t want to have to open multiple tools when it should all interoperate together for the same effective high-level task. Unifying it all just allows for better (hypothetical) integration between all the parts. Just remember — integration doesn’t mean it has to be bad or slow (current Xcode can always be improved).
- adrusi 6y agoMultiple tools doesn't mean that they can't interoperate. It's just that Apple (and everyone else) has given up on graphical IPC.
- colejohnson66 6y agoWhat’s a graphical IPC? How would processes communicate graphically?
- 6y ago
- blumomo 6y agoWe are producing a white-label mobile app which also runs on Apple devices. It's part of our build chain to modify bespoken Xcode project files. Of great help is this node library [0] which allows automating our build process which includes modifications to the Xcode project file. [0] https://github.com/apache/cordova-node-xcode https://github.com/apache/cordova-node-xcode
- oauea 6y agoWatch out, Apple might call your business model "spamming the app store": > Don’t create multiple Bundle IDs of the same app. If your app has different versions for specific locations, sports teams, universities, etc., consider submitting a single app and provide the variations using in-app purchase.
- NateEag 6y agoAs someone who has maintained such a system, there is a very real risk of this. If the app is content-heavy, and that content varies between each instance of the app, they're more likely to be okay with it, but it is still a difficult road fraught with pain and risks.
- blumomo 6y agoThanks, I appreciate your hint. We are aware of the app store policies -- and we are not affected. Our apps are owned and customized by our customers and each app has their own content. Imagine our solution as an app building toolkit.
- osrec 6y agoEvery developer in my company unanimously hates Xcode, and we only use it if a client explicitly insists on an iOS app. Otherwise, it's PWAs all the way for 99% of use cases.
- viktorcode 6y agoOut of curiosity, what do they like to use for development? Over the years I used numerous IDEs, and for me Xcode was the least problematic. None was great.
- osrec 6y agoSome of my devs use Eclipse, some VSCode, some Atom, some Vim; it really varies. Sometimes, they'll use one for a particular language, and switch to another for a different language. I think every editor/IDE has its flaws, but all my devs unanimously seem to hate XCode.
- swiley 6y agoUsers prefer PWAs too.
- matchbok 6y agoIt's such trash. For my personal projects, XcodeGen is a lifesaver. How Apple thinks that a single god file is a good idea is crazy to me. No other build tool needs this. https://github.com/yonaskolb/XcodeGen https://github.com/yonaskolb/XcodeGen
- quux 6y agoWe use xcodegen at my work and it’s awesome. A similar project from Google is Tulsi [1] but even though it can also generate xCode project files I think it’s more geared towards making iOS projects work well with Bazel. [1] https://tulsi.bazel.build/ https://tulsi.bazel.build/
- aaronbrethorst 6y agoI cannot imagine working on an iOS application that is meant to be maintained by multiple people that does not use Xcodegen. Additionally, it is the only sane way I've found of handling whitelabel application development. Here's an example for anyone who wants to see it in action: https://github.com/onebusaway/obakit https://github.com/onebusaway/obakit
- mayoff 6y agoYep, the pbxproj format sucks. The good news is that each version of Xcode adds more power to the Swift Package Manager manifest file.
- Turing_Machine 6y ago> you need to replace every backslash with eight backslashes and then it will work. Eight? Eight? Good Lord.
- viktorcode 6y agoOn my job we used custom Xcode file parser / editor, and serialisation part is trivial. The file paths are not modified manually in any way. The complex part is the model, PBXProj object.
- mort96 6y agoWell, it grows exponentially. You want to end up with one backslash `\`. After one escape, you get `\\`. If you escape the escaped string, you get `\\\\`. After another layer, you get `\\\\\\\\` for a single backslash. Here's a somewhat realistic example: You need a piece of javascript in a string literal, and you need that javascript to generate a regex matcher for a single backslash. You could do that like this: let code = "new RegExp(\"\\\\\\\\\")"; It's not _that_ uncommon when you need to marshal one language through many layers of languages (in my example, the regex language being marshalled through a javascript string literal and then another layer of javascript string literal). In XCode's case, two layers are obvious; you want a backslash, so you need the string which is fed to the shell to contain `\\`, so your XCode string literal has to be `"\\\\"`. For some unknown reason, there's a third level of escapes which takes us to `"\\\\\\\\"`.
- mistahenry 6y agoI’ve used the Cocoapods tool Xcodeproj to facilitate really nice Workflows that Xcode didn’t provide for me out of the box. I don’t need this in every project but when I do it’s a really nice API for manipulating the pbxproj files https://github.com/CocoaPods/Xcodeproj https://github.com/CocoaPods/Xcodeproj
- lstamour 6y agoJust wanted to chime in that you can, in fact, convert old ASCII plist files to modern JSON and XML and then convert them back: https://stackoverflow.com/a/46929480 https://stackoverflow.com/a/46929480 shows how to use plutil in one direction, and you can convert back using the “pl” utility, I believe. It’s a bit confusing that one command converts to modern formats and a different command can convert modern formats back to legacy formats. Under “standards”, the man page appears to have the following cheeky warning for pl: “The pl command obeys no one's rules but its own.” https://www.unix.com/man-page/osx/1/pl/ https://www.unix.com/man-page/osx/1/pl/ or just type “man pl” or “man plutil” at Terminal. Here’s an example of how to read and write an xcodeproj file using Python and these two utilities: https://gist.github.com/brunogama/3929457 https://gist.github.com/brunogama/3929457
- fiddlerwoaroof 6y agoThis tool doesn’t always work because plists can contain arbitrary Objective-C objects. However, there’s a relatively nice objective-c API that can be used to decode them losslessly that I used to extract data from Safari’s reading list l: https://github.com/fiddlerwoaroof/objc-lisp-bridge/blob/master/objc-data-extractors.lisp#L18-L20 https://github.com/fiddlerwoaroof/objc-lisp-bridge/blob/mast...
- setpatchaddress 6y agoplists absolutely cannot contain arbitrary Objective-C objects. They support a subset of Foundation container and value types and are not extensible to contain other types.
- fiddlerwoaroof 6y agoAny Codable can be written to or read from plists, right? Anyways, it’s definitely true that plists support a superset of the data types supported by JSON: plutil will not convert the Safari bookmarks file to JSON, for example.
- 6y ago
- bartvk 6y agoWhat an incredible negativity here in the comments. I’d like to provide a counter and say that I’ve been developing in Xcode for a number of years now, and I think it’s fine. Is it great? No. But it’s fine and I’m very productive. My projects are generally small, meaning not more than 100-150k lines, maybe that is what causes problems for other people? Anyway, I’ve had good, solid fun with SwiftUI in the most recent year or two. The Preview canvas didn’t always work, but I usually found a workaround.
- akmarinov 6y agoPretty much this.
- josephg 6y ago> What an incredible negativity here in the comments This might seem strange, but I think the negativity here makes sense, and is justified on multiple fronts. On a technical front, Xcode is pretty awful. It’s slow and unstable, and seems to have only gotten worse over the last decade. Many comments here express this in detail. This matters so much because tools become an extension of our bodies. Using bad tools makes us feel ineffective, weak and slow. If I can’t trust Xcode to receive keystrokes (yes, a real bug I encounter frequently), my brain interprets that bug as me being physically impaired and unable to type. It’s awful. This is made so much worse because Xcode - and any bad product from Apple - betrays Apple’s promise to it’s customers. Apple’s promise is “we sell premium products which are worth the extra cost because they’re delightful. Buy from us and we’ll take care of you”. Steve jobs used to say this sort of thing quite explicitly. This is why people hold Apple to a higher standard - because Apple promises a higher standard with their branding and their prices. It wouldn’t matter so much if Xcode were part of an open ecosystem and we had choice - I wasn't angry a few years ago when Atom was laggy and slow. I just shrugged, uninstalled and used something else. But iOS devs are mostly locked in. They have nowhere to go. And practically speaking, people from all over the tech industry are on HN. Plenty of people at Apple are here - even if they can’t say so. Hopefully a bit of public shaming will be read by someone at Apple with the authority to right the ship. We can hope.
- catchmeifyoucan 6y agoSometimes Xcode opens files on my computer like Json and XML as a default. I just know that everytime I accidentally open a file, I’m screaming to myself inside, “No, no” as the splash screen begins loading. I also find Xcode as my forcing factor to keep upgrading MacOS.
- saagarjha 6y agoYou should probably change the file associations for those to something else.
- viktorcode 6y agoPro-tip: in your model you can serialise Xcode project as XML format (that is, PLIST v2) and Xcode will correctly parse it. By default it uses PLIST v1, which looks like JSON, but differs in some things. I used standard 'description' obj-c call to produce PLIST v1, maybe there's another way to do it I don't know about.
- makecheck 6y agoThere is some “hope” with Swift... Just as SwiftUI has allowed me to ditch endless awful Apple UI file formats, Swift Packages are a relatively simple way to avoid much of what might otherwise require the rest of Xcode to configure. I feel like there may be an internal tug of war happening in Apple but I sincerely hope the people advocating for damn-near-undiffable file formats will lose.
- wingerlang 6y ago> Just as SwiftUI has allowed me to ditch endless awful Apple UI file formats I’ve not used storyboards/xib in years, in both objc and swift.
- Keyframe 6y agoI only used Xcode a handful of times, so bear that in mind, but out of those handful of experiences it reminded me all of Metrowerks days in a bad way and if almost nothing has changed... decades since.
- fredrikholm 6y agoiOS development nearly broke me. It's the only language/platform/runtime that have hampered my ability to perform my job to the extent where it's taken a toll on my well being and confidence . * Having to buy a computer, use a new OS, use a new editor and buy a new phone to just get started. * MacOS, XCode and/or iPhone updating and breaking my own and third party code ad hoc. * Having to know/learn C, Obj-C and Swift 1, 2, 3, 4 and 5. Being forced to constantly translate between these, and check timestamps on documentation/SO/guides to determine how much use there is in even skimming it as the amount of deprecation and half-implemented things that I'm not supposed to use in production means my confidence in implementation is near zero. * Brittle pipelines, impossible fresh installs that break in the weirdest ways (Ruby? What?), publishing and generally interacting with Apple making otherwise quick actions take days. * XCode not working great with GIT, having to reboot it when it randomly stops working all together, input latency, code highlighting that half of the time doesn't work at all or is very slow (on a brand new M1). I work as a consultant, and often have to learn new languages/runtimes for my job, but nothing has been as bad as iOS.
- SoiGubz 6y agoApple's tooling peaked while it was still OpenStep. It's been a sharp downhill ride since then.
- mrlonglong 6y agoI get even better joy creating CMake files, they just work.
- c-smile 6y agoIs it practically possible to create GUI application for MacOS without using XCode? I am building my Sciter using premake5 on Win/Lin/rPI/Mac. Premake5 is very useful to generate projects and makes for different platforms/IDEs. But on Mac premake5 is really works to create .dylibs only - seems like to generate GUI app on Mac XCode is the only option, is it?
- slmjkdbtl 6y agoIt's very possible, check out code for glfw, sdl, and sokol and grep for "cocoa", "mac", but you do need ObjC, which can be written in C files with -ObjC flag.
- saagarjha 6y agoDepends on what "practical" means to you. For example, you can paste import AppKit _ = NSApplication.shared NSApp.setActivationPolicy(.regular) let window = NSWindow(contentRect: NSRect(origin: .zero, size: CGSize(width: 500, height: 500)), styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: true) window.title = "Test" window.center() window.makeKeyAndOrderFront(nil) NSApp.activate(ignoringOtherApps: true) NSApp.run() into a file and run it to get a window.
- sjg007 6y agoI like swift and swiftui.. I get it’s not cross platform but my apps are simple.
- trangon 6y agoXcode has aged very poorly and Apple top-level management refuses to invest further headcount into improving it in general. They should port their custom tools like IB, view debugger, etc. over to Visual Studio Code and get out of the IDE game.
- phendrenad2 6y agoApple's dev tools are a huge liability for the company, basically the corporate equivalent of a superfund site. Sooner or later they'll have to address the issue and rewrite the whole thing from scratch, but by the time they do, it may be too late. The only thing that can compel them to fix it is an competitor eating into their market share, and once there is a better alternative, I think people may switch en masse. Mobile apps are mostly just some UI on top of an API, so switching everything to a new OS should be trivial.
- Fusion_Pizza 6y agoFuck Xcode
- knlam 6y ago> You know, I really wish this file was XML instead. Enough said. Xcode is the worst devtool I ever used