Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pctechtv

macrumors member
Original poster
Sep 3, 2013
52
1
Microsoft LINQ is a component of programming in their systems. I am interested in how it can turn local assets like text and XML files into query-able content. Does Cocoa have anything like this. Thanks
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
The approach to how you do something like LINQ differs quite a bit with Cocoa and Foundation.

NSPredicate enables a similar sort of filtering on any collection of objects using KVO, although I think LINQ’s syntax is better. That gets you the querying part, and the upside is that it doesn’t really matter where the data came from. Just make sure your objects are KVO-compliant, and use the standard collection types.

For the loading part, you need some sort of serialization. Apple provides serialization for plists and JSON, but in general has very little to no XML support baked into Foundation. You’d be looking for a third party serialization framework if you want XML in this case. Or just use JSON.

EDIT: And if we are talking about Swift, then you have similar tools baked into the runtime for standard collections that more closely aligns with LINQ’s syntax for in-memory objects. You still need to use some form of serialization like above.

Really, LINQ’s strength is that it can also query against something like SQL with the same syntax, allowing you to query data that isn’t in memory. While with NSPredicate, it only works that way with CoreData. I suppose with a proper SQL back end on CoreData, you could do it though, but you are looking at a 3rd party bit of code for that. The real thing that bothers me about LINQ is that they introduced yet another way to parse XML to enable it rather than extending one of the two existing ways .NET already had by making their collections complaint. Forcing you into either the new or old way of dealing with XML rather than making it easy to do both.
 
Last edited:
  • Like
Reactions: pctechtv
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.