All Posts For: C Stuff

Jun 6 2013

Inside the Bracket, part 2 – data invocation

Last time we took a look at the motivations behind Objective-C message sending. It’s a layer of indirection that lets one chunk of code treat other, perhaps unrelated, chunks of code in a uniform manner. “I have a pile of views here, I shall draw them all with -drawRect:, and I don’t care if the views are Buttons, Sliders, or World Maps.” There’s a loop that hits a collection and sends the same message to a bunch of objects:

for (NSView *view in visibleviews) {
    [view drawRect: view.bounds];
}

Objective-C performs this magic by having a collection associated with each object.…

May 22 2013

Illuminating ARCLite

Today we’re going to look at using Objective-C’s array and dictionary subscripting syntax with older iOS and OS X versions.

If you haven’t already, I can’t recommend enough reading Part 1 and Part 2 of Mark Dalrymple’s excellent two-part series about Objective-C’s literal/boxing/subscripting syntax.…

May 17 2013

Leveling Up

So. That Clash of the Coders Thing. Kind of nice being able to flex mental muscles over a 72-hour sleep-deprived Dr Pepper-infused period of time, performing acts of violence upon the Objective-C runtime, UIApplication, and the layer stack. It was a blast being able to use all my platform knowledge with the express purpose of subverting it.…

May 2 2013

Static Cling

I was hanging out on the #macdev IRC channel on Freenode the other day when someone asked a question: “static has different meanings based on the context it is placed in, right?”. Indeed, it has different meaning. And yet it’s the same.…

Apr 11 2013

Spelunkhead

You can find all sorts of interesting and useful stuff in Apple’s header files. Don’t be afraid to explore them. I usually troll through the headers when a new major SDK version comes out (like IOS 7 probably will be this year) to see what’s new.…

Nov 5 2012

Fast Enumeration, part 2

Fast Enumeration, part 1 covered what fast enumeration is, NSEnumeration a bit, and introduced adopting fast enumeration in your own classes by doing a simple pass-through to Apple’s collections. This time around it’s time to look deeper at the central Fast Enumeration call, which I’ll refer to as countByEnumeratingState:

- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState *) enumerationState
                                   objects: (id __unsafe_unretained []) stackBuffer
                                     count: (NSUInteger) length;

OK.…

Nov 1 2012

Fast Enumeration, part 1

Fast Enumeration was introduced into Objective-C back in the 10.5 days. It’s the feature that lets you succinctly iterate through a collection:

NSArray *strings =
    [NSArray arrayWithObjects: @"greeble", @"bork", @"hoover", nil];

for (NSString *thing in strings) {
    NSLog (@"Woo! %@", thing);
}

Back in the moldy old days, we had to use NSEnumerator to do the same thing:

NSEnumerator *enumerator = [strings objectEnumerator];
NSString *thing;
while ((thing = [enumerator nextObject])) {
    NSLog (@"woo.…
Older posts