Search code examples
objective-cxcode4

How to add multiple source members with main into the same Objective C project in Xcode?


I am currently learning Objective C programming using Xcode. I am wondering how to have multiple main programs, i.e. source members with main method in it, in a single project? It is a bit inconvienient to put just one in each project, as I would have to create tons of them through my learning process. Or is there any better way to do it? All I want is to place multiple independent executable programs in a single project, though I only need to run on each time. Thanks a lot.


Solution

  • This is much more trouble than it's worth. Just create tiny test projects. I've got a huge directory of them that I throw away from time to time. I also constantly re-create a project called "Test" for building little projects.

    For really, really tiny things, I do sometimes create a simple test.m file that has its own main and compile it by hand:

    gcc -framework Foundation -o test test.m
    

    But in that case I don't bother with Xcode.

    EDIT You of course could replace gcc above with clang. For projects so small that I'm doing this, it hasn't been worth changing my muscle memory....