So, thanks to blocks, Apple’s new extension to C, you can now do basic object-orientation. Have a look over at GitHub for a short example on how to do it.

To break it down, an object is a struct, which contains both fields and blocks which act as the object’s methods.

typedef struct {
	Object super;
	char *_value;
	const char *(^getValue)();
	void (^setValue)( const char * );
} String;

This creates a String object which inherits from Object and has a field _value, and methods getValue and setValue.

More to come… maybe.

blog comments powered by Disqus