Adding Box2D to Xcode

Grab the Box2D folder and drag it into your Xcode project.



Make sure copy items and the correct target are both checked.


In the project build settings, filter by “user”.


Under ‘User Header Search Paths’ add a . for the current directory and select recursive.


Set ‘Always Search User Paths’ to YES.


For the given source file, you need to change the extension to *.mm


Doing so, changes the default type to Objective-C++.


Finally, import Box2D and begin your journey.



It’s hard to find an example using CGDataProviderCreateDirect, so here’s a quick snippet:

static unsigned int* data; // used for manipulating pixel data directly

const void * getBytePointerCallback(void *info)
	return (void*)data;

@implementation SomeView

- (void)createImage
    CGDataProviderDirectCallbacks callbacks;
    callbacks.version = 0;
    callbacks.getBytePointer = getBytePointerCallback;
    callbacks.releaseBytePointer = NULL;
    callbacks.getBytesAtPosition = NULL;
    callbacks.releaseInfo = NULL;
    float w = self.layer.frame.size.width;
    float h = self.layer.frame.size.height;
    w *= [UIScreen mainScreen].scale;
    h *= [UIScreen mainScreen].scale;
    int numComponents = 4;
    uint dataLength = w * h * numComponents;
    data = malloc(dataLength * sizeof(uint)); // TODO: free
    uint r = 255;
    uint g = 0;
    uint b = 0;
    for(int i = 0; i < dataLength; ++i)
        data[i] = 255 << 24 | b << 16 | g << 8 | r;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGDataProviderRef bitmapProvider = CGDataProviderCreateDirect(data,dataLength,&callbacks);

    CGImageRef bitmap = CGImageCreate(w,
                                      8,    // bits per component
                                      8*numComponents,  // total bits
                                      w*numComponents,  // bytes per row
    self.layer.contents = (__bridge id)(bitmap);

couchdb reader_acl

I installed CouchDB 1.0.1 with MacPorts 1.9.1 and quickly ran into problems:

  • The ‘attachments’ test hung in Chrome 6.0.472.55. I ran the same test in Firefox 3.6.9 and it worked.
  • The ‘reader_acl’ failed with an exception.
  • I couldn’t create an admin.

The couchdb.log certainly had errors but I couldn’t find a solution online. I tried uninstalling the port and reinstalling with no luck. Eventually I gave up and downloaded CouchDBX. Creating an admin worked but it also had problems running the Test Suite (I had to Force Quit).

Then I tried Homebrew. After installation I ran the Test Suite with 100% success and was able to create an admin! Awesome, now I’ll just add org.apache.couchdb to launchctrl…hmm it’s not under /Library/LaunchDaemons or /opt/local/Library/LaunchDaemons. After a little digging I eventually found it under /usr/local/Cellar/couchdb/1.0.1/Library/LaunchDaemons/. Only a few steps remain:

  • Copy org.apache.couchdb.plist into /Library/LaunchDaemons
  • Change the value under the UserName key to your user short name (hint: look under /Users)
  • sudo launchctl start org.apache.couchdb or you can test it for sure by restarting (shortcut key: Control-Command-Eject)

Everything now appears to be in working order.

adding FLEX_HOME and building as3-signals on a mac

Fire up a terminal:

  • cd ~/Library/SDKs
  • git clone

You can find the above url on the as3-signals homepage on github. My personal pref is to put 3rd party libraries under ~/Library/SDKs

If you look inside the as3-signals dir, there is a build.xml file which requires a FLEX_HOME variable to be set. So, I downloaded the Flex 4 SDK and dropped it under /Developer/SDKs/flex_sdk_4. In the terminal, we need to set the env variable FLEX_HOME. First, lets check if you have an existing one defined. In the shell, type

  • env

You should see a list of defined variables. If you need to remove an existing FLEX_HOME, you can do so by typing

  • export -n FLEX_HOME

Otherwise, you can add a new FLEX_HOME by typing:

  • FLEX_HOME=”/Developer/SDKs/flex_sdk_4″
  • export FLEX_HOME

If you type env again FLEX_HOME is now added to the list. Now we can build as3-signals.

  • cd ~/Library/SDKs/as3-signals/
  • ant

Ant looks for a build.xml by default. Upon a successful build you’ll find a .swc in the bin folder.

Note: Setting FLEX_HOME this way will only last for 1 terminal session. If you’d like a more permanent solution, see:

patch 8

As I wade through the tutorials, I stumble upon objects that appear quite handy, like the js object. The js object could have vastly simplified my development of patch 7. How so? Well, like this:


Ahh…so much cleaner than the mess I had before. Modifying the Java code to Javascript was trivial, here’s the code for sketch0.js:

outlets = 0;

// global vars
var offset = 20.0;
var radius = 50.0;
var centerX = 50.0;
var centerY = 50.0;
var x = 0.0;
var y = 0.0;
var angle = 0.0;
var frequency = 2.0;
var counter = 0;
var coordsX = new Array(180);
var coordsY = new Array(180);

function bang()

function radians(angle)
    return angle * Math.PI / 180;

function draw()
    outlet(0, "clear");

    // calculate point
    x = centerX + Math.cos(radians(angle)) * radius;
    y = centerY + Math.sin(radians(angle)) * radius;

    // draw black circle
    outlet(0, "paintoval", offset, offset, radius*2+offset, radius*2+offset, 0, 0, 0);

    // draw red circle (10 pixels in diameter)
    outlet(0, "paintoval", x+offset-5, y+offset-5, x+offset+5, y+offset+5, 255, 0, 0);

    // draw green circle
              0, 255, 0);

    // draw prev point
    for(var i = 0; i < counter; ++i)
        outlet(0, "setpixel", coordsX[i], coordsY[i], 0, 0, 0);

    // cache prev point
    coordsX[counter] = centerX + radius + counter + offset;
    coordsY[counter] = y + offset;

    // adjust counter and angle
    angle -= frequency;
    if(angle <= -360)
        angle = 0;
        counter = 0;

Another possiblity is to swap the lcd object out in favour of jsui, but let’s not get carried away.