Tag Archives: osx

Create a new project and select Other from under the OS X category when the dialog appears, and then choose External Build System:

Tap to enlarge

In the next page, give your project a name “product name” and then in the “build tool”, choose the path of your Python interpreter. If you don’t know where your Python interpreter is, open Terminal and type in which python to get the path to the interpreter, like so:

Tap to enlarge

Then save your project on disk

From the Product menu, choose Scheme and then Edit Scheme or just Option-click the little Play button on top left of Xcode. Now you should see the Edit Scheme screen which looks like this:

Tap to enlarge

Now tap on the Info tab on top of the dialog and then press on the Executable combo-box (which currently says “None”) and then from the list, choose “other…”

Tap to enlarge

An open-dialog will appear waiting for you to select your build tool, again! This is a bug in Xcode. So press the Cmd+Shift+G button in the open-dialog and when the “Go to the folder” dialog appears, enter the path of your Python interpreter again like so:

Tap to enlarge

Once you are done, press the Go button and then press the Choose button

Back in the Edit Scheme dialog, uncheck the “Debug executable option as you don’t want Xcode to attach the LLDB debugger to Python. That’s not useful. This step is very important.

Tap to enlarge

Now tap on the Arguments tab and then under the “Arguments Passed on Launch”, press the + (plus) button and then type in “test.py” without the quotation marks, like so:

Tap to enlarge

Now tap on the Options tab and then under the “Working directory” section, tap the “Use custom working directory” and then tap on the little Folder button. Once the open-dialog appears, choose the root folder of your Xcode project:

Tap to enlarge

Now press the Close button to close the Edit Scheme dialog

Press the Cmd+N combination on keyboard or just select from the menus, File->New->File…

In the New file dialog, from the left hand side, choose OS X and then Other and then choose Empty and then press the Next button:

Tap to enlarge

Name your file “test.py” (without the quotation marks) and then ensure that you are saving it under your project’s main folder, the same folder that you set your “Working directory” to a few steps ago. Once you are done, press the Create button.

Tap to enlarge

Write a simple Python script in your “test.py” file like so:

Tap to enlarge

Now run your application and have a look at the console in Xcode to see your Python script successfully executed:

Tap to enlarge

That was it really. Good luck everyone. If you have any questions, just let me know.

A lot of times when working in a team, you would write a class, or add an enumeration to an existing class or add a new property. Some times, you might need to tell other programmers who work on the same code-base that a property, enumeration or a method that you wrote is now becoming deprecated and perhaps a new version of the API introduces a new property/enumeration/method that programmers need to use instead.

This is where LLVM can be very useful. Obviously, if you are the only programmer in a project and not developing an API for others, this might not be of much use to you. But if you are used to working in a team, knowing this trick is an absolute necessity.

Let’s say we are writing an enumeration that at the time of writing (let’s assume at the time of writing this enumeration, iOS 5 was the latest iOS version), everything was fine like so:

Now let’s say iOS 6.0 is introduced and you are thinking to yourself “Oh that Ultra Fast item in the enumeration is just not very good and I think I have to remove it”. So what to do now? The solution is using __attribute__ like so:

Deprecating an enumeration value in Objective-C

The availability attribute can have the following keys:

introduced: this will be the version of the operating system (iOS, Mac OS X) where the API was introduced first.

deprecated: this is the version of the operating system where the API was deprecated (ready to be removed from the API in later versions of the API)

obsoleted: the version of the operating system where the API is completely removed and is no longer supported.

message: the message to display to the programmer in Xcode.

As you can see, right in front of the availability attribute, we can write “ios” or “macosx” to denote if an API is (un)available for iOS or Mac OS X respectively.

Now let’s assume iOS 7.0 comes along and we want to completely stop our support for the “ultra fast” enumeration value. All we have to do is to add the “obsoleted” key to the availability attribute like so:

I hope you enjoyed this tutorial. Let me know if you have any questions 🙂

Like this:

Edit 1 (20th October 2014): Xcode 6.1 instructions can be found here: https://vandadnp.wordpress.com/2014/10/20/building-and-running-python-scripts-with-xcode-6-1/

So you have installed Python and you want to use Xcode to write and run your Python scripts… is that correct? Ok then, follow these steps to create a simple project and run it with Python using Xcode 4.x…

Open Xcode and select File->New->Project…

From the left hand side, under the OS X category, select Other

Now on the right hand side, select External Build System and press the Next button, as shown below

Click to Enlarge

Now open a Terminal window and type which python in it, and keep the results in mind or just keep Terminal open for future reference, as shown below. This will tell you where Python is installed on your system.

Click to Enlarge

As you can see, in my case Python is installed under /usr/bin/Python

Now back to Xcode, set the following values on the second screen of project creation:

Product Name: test

Organization Name: company

Company Identifier: com.company

Build Tool: enter the path to Python which we retrieved from Terminal. I have entered /usr/bin/Python (see below)

Once you are done entering all four values, press the Next button.

Click to Enlarge

Once you pressed Next, now you should choose where you want to save your project, save it somewhere that makes sense for you. I am going to save it in ~/Desktop/Development/Projects/Python/Sandbox/test/ as that’s how I have structured my development environment. Once you are happy with the folder that you are saving your project in, press the Create button in Xcode’s dialog, as shown below

Click to Enlarge

Now select the “test” target from the breadcrumb menu on top left corner of Xcode’s main window and choose Edit Scheme, as shown below

Click to Enlarge

In the Edit Scheme screen, on the left hand side, choose the Run option. Then on the right hand side, choose the Executable section and press the Other… item. This will open an Open dialog for you asking you to choose the binary of Python. For me, Python was sitting in /user/bin/python as you saw earlier. So in Mac, I press Cmd+Shift+G to “Go to Folder” and then I type in /usr/bin/, as shown below and then press Go:

Click to Enlarge

Now that you are in the folder that contains the Python binary, find and pick the binary and press the Choose button

Back in Xcode, on the same Scheme window that we were on before, under the Debugger section under Info, make sure that you choose None. This is very important.

Click to Enlarge

Back in Xcode, on the same Scheme window that we were on before, navigate on the right hand side to the Arguments tab and under the Arguments Passed On Launch, press the + button and type test.py, as shown below:

Click to Enlarge

Now go to the Options tab, under the Working Directory, click the Use custom working directory and then put the full path to where you are intending to save your Python files in this project. My project is at ~/Desktop/Development/Projects/Python/Sandbox/test/ and I’m intending to save my first file as ~/Desktop/Development/Projects/Python/Sandbox/test/test.py so I will choose ~/Desktop/Development/Projects/Python/Sandbox/test/ as my working directory, as shown below:

Click to Enlarge

We are now done with the Schemes. Press the OK button to close this window.\

In Xcode, from the Menus, choose File->New->File…

From the left hand side of the dialog, under the OS X section, choose Other and then on the right hand side, choose Empty and press the Next button, as shown below:

Click to Enlarge

In the next screen, make sure that you set the value of Save As as test.py. This is what we have been preparing our Scheme for, that we are going to have a file called test.py that needs to be passed to the Python interpreter. Have a look at the following screenshot. Once you are done, press the Create button:

Click to Enlarge

Now enter the following code in your test.py file: print “It works!”, as shown below:

Click to Enlarge

As the final step to make sure everything is working fine, in Xcode, from the menus, choose Product->Run, the Debugging Area will popup and show you the output of the print command like so:

Click to Enlarge

Lovely, it’s all working. I hope this tutorial helped you. If you have any questions or suggestions, please leave them in the comment sections down below…

You can see right away that c++ is a symlink to clang++ and clang++ is a symlink to clang. What a mess!

Now let’s find “cpp”:

ls -la cpp
ls: cpp: No such file or directory

Oopsy daisy, it’s not there. That’s one of the issue a lot of developers will be facing. So let’s remedy this by first creating cpp as an alias. We want this alias to be permanent between Terminal sessions so we put it in our bash_profile and we also have to make sure the toolchain bin url highlighted above is in our path:

vim ~/.bash_profile

And then change the content of your bash profile so that your path includes:

There choose your platform and the install process will start automatically. This will download a .dmg package to your machine. Simply follow the installation process. After installation, you should be able to find Git in the following folder:

/usr/bin/git

And since this folder is already added to your path, you can simply access it in Terminal by typing git