All Posts For: C Stuff
Jun
6
2013
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
23
2013
What is something that we use every day as a Mac or iOS programmer? Objective-C. What do we use every day in Objective-C? Those square brackets. How many times a day do you type something like this?
[someObject doSome:stuff for:reasons];
Ever wondered what’s really happening inside those square brackets?…
May
22
2013
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
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
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
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.…
Jan
8
2013
One More Thing writer spends a week at bootcamp, sharing his journey
Jan David Hanrath, co-founder of One More Thing, a popular blog serving the Dutch Apple community, spent a week at Big Nerd Ranch Europe bootcamp to become an iOS developer.…
Nov
8
2012
Fast Enumeration, part 1 covered what fast enumeration is. Part 2 covered the method countByEnumeratingState, which is the centerpiece of fast enumeration. This time around there’s actual code which implements a collection that can be fast enumerated, without cheating and falling back on one of Apple’s collections.…
Nov
5
2012
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 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