Question

I am using Xcode to learn C. I made a project named Learn C, and I would like this to contain many exercises, like ex11.c, ex12.c, etc. However, this does not work, because all my exercises need the main function, but only main.c can have it.

In Eclipse, I would be able to make a workspace named Learn C, and have many .java files in it, like ex11.java, ex12.java, etc, to keep myself organized.

Does anyone know how I can recreate this in Xcode?

Thanks!

Was it helpful?

Solution 2

Start by creating a workspace:

  • Open Xcode.
  • Pull down the File menu and select New Workspace...
  • You will be prompted for the name of the workspace and optionally a target folder to create it in. Select New Folder in the lower right corner and create a folder called Learn C. Then, select Save. A new workspace will be created in your new folder.

Once you have that you can create new projects within the new workspace. To do this...

  • Right-clck anywhere in the workspace explorer on the left-side pane of Xcode and select New Project....
  • Select OS X Application from the left pane, then (if this is just C code) Command Line Tool from the right pane. Then select Next.
  • Enter the name of your product (in your case, Ex1 would be your likely first product). Select the appropriate language, in your case C.
  • On the next wizard pane, when prompted for the location of the new product, the default settings should be sufficient, but in case they're not set correctly, make sure both Add To: and Group: have the Learn C workspace selected. Press Create.
  • To select which project you're building at any given time, select the active "scheme" by navigating the Product/Scheme menu and clicking on the project you want to build, or select the scheme using the button bar (its the bottom immediately to the right of the "Stop" button in the upper-left of the bar).

This should create a new project in the Learn C workspace. You can repeat the project-creation steps above (not the workspace creation; you already have one of those) for as many projects as you want, so long as their names are unique. Once you get the hang of this, you will be able to share code between projects using the advanced capabilities of the workspace and project management features, but for now this should be enough to get you going.

More information can be found on the Apple Xcode Developer Website (assuming you've shelled out your $99 annual developer fee). There is a wealth of info on Xcode, and though it (imho) isn't as snazzy as the likes of Visual Studio on Windows, it becomes natural after some time (like all things). The section titled Maintain Your Code and Other Resources in Projects or Workspaces will probably lead you further down the path you're interested in pursuing.

Best of luck.

OTHER TIPS

You can do this in Xcode as well. For each exercise, you need to create a new target. To do that, open your Xcode project, click on the Project Navigator tab, and select the project. Then, from the "Editor" menu, select "Add Target". If you're working with examples from a book or web page that isn't Mac-specific (or iOS-specific), you'll want to select "Command Line Tool" as the type of target. Xcode will create the new target and you can add your new ex*.c file to it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top