3 ms·
As a C# dev without a real project for the iPhone, I couldn't get past how cluttered the same code looked. It would be nice to hear how the class library compa
by joshuaellinger 13y ago
As a C# dev without a real project for the iPhone, I couldn't get past how cluttered the same code looked.
It would be nice to hear how the class library compared to VCL.
- Strilanc 13y agoAssuming you mean the BCL (base class library). In my experience, the BCL is more comprehensive. For example, the iOS framework lacks a built-in queue or a sorted list (as far as I know). One thing Obj-C does have, that I miss in C#, is equality methods defined for collections. You can compare the contents of arrays and sets and dictionaries without writing any special code or using special methods. (Although you can break it by creating cyclical structures, since it does naive recursion instead of unification.)
- jrmg 13y agothe iOS framework lacks a built-in queue The convention for this sort of thing is to use an NSArray, inserting at position 0 to enqueue and removing the last object to dequeue. The NSArray class is actually written in a way that makes this efficient (for some great analysis see http://ridiculousfish.com/blog/posts/array.html http://ridiculousfish.com/blog/posts/array.html). or a sorted list (as far as I know) For sorted lists, I think you're right, you'd have to do it yourself. The question a Cocoa old-hand might ask would be if you _really_ need it to be always-sorted, or if you can keep your objects in an array, dictionary or set and sort them before using or iterating - or maybe just iterate the collection in a specific order instead of sorting it at all. If you do need to keep it sorted all the time, note that _inserting_ into an NSArray is also more efficient than you might assume. Keeping a sorted NSArray up to date yourself might not be expensive (it would be a bit more complicated than an auto-sorting class though, of course).
- jawngee 13y agoYou have to sort it yourself, but it's super easy. For NSArray's: NSArray * sortedArray=[array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { // your code here }]; For NSMutableArray's: [marray sortUsingComparator:^NSComparisonResult(id obj1, id obj2) { // your code here }];