«

»

Aug
24

Microsoft’s LINQ and Apple’s Cocoa Key Paths

I’ve been working with Objective-C recently, and ran across a discussion of Cocoa Key Paths and Microsoft’s LINQ. With Microsoft LINQ (Language Integrated Query), you can do things like this:

public void Linq1() {
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

var lowNums =
from n in numbers
where n < 5
select n;

Console.WriteLine("Numbers < 5:");
foreach (var x in lowNums) {
Console.WriteLine(x);
}
}

Resulting in:

4
1
3
2

That’s pretty cool. More complex examples make a built-in query language pretty handy. You can see more examples on Microsoft’s Linq examples page.

Cocoa has a similar feature, called key-value coding.

You can read more about how Apple’s OS X handles this in Matt Long’s posting over at the interestingly named “Cocoa Is My Girlfriend” blog.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>