NSDictionaries and NSArrays aren't typesafe... you use methods like objectForKey: or objectAtIndex:, but you can't be certain of the type you'll be getting back, beyond the fact it'll be an NSObject.
In the past, I never worried about it because I haven't worried about maintaining my code or ensuring that other people can easily follow it. But now I'm thinking... it seems like using NSDictionary and NSArray are really poor choices for keeping your code easy to follow.
Rather than store and pass data around in generic classes like NSDictionary and NSArray, wouldn't it be better to make your own NSObject subclass and load it up with properties that store specific types?
I'm curious, does anyone have some example scenario where it's a better idea to use an NSDictionary or NSArray rather than your own class?
I guess, while I'm at it, I may as well ask this too... is there any equivalent to a C++/Java Vector class in Obj-C, where you can specify the type of object that a specific collection instance will store? Will you get compile time errors for misusing it? If not, are there any ideas for how you might make your own? Is there any way to add your own compile time checks that generate warnings/errors for when your classes are misused?
In the past, I never worried about it because I haven't worried about maintaining my code or ensuring that other people can easily follow it. But now I'm thinking... it seems like using NSDictionary and NSArray are really poor choices for keeping your code easy to follow.
Rather than store and pass data around in generic classes like NSDictionary and NSArray, wouldn't it be better to make your own NSObject subclass and load it up with properties that store specific types?
I'm curious, does anyone have some example scenario where it's a better idea to use an NSDictionary or NSArray rather than your own class?
I guess, while I'm at it, I may as well ask this too... is there any equivalent to a C++/Java Vector class in Obj-C, where you can specify the type of object that a specific collection instance will store? Will you get compile time errors for misusing it? If not, are there any ideas for how you might make your own? Is there any way to add your own compile time checks that generate warnings/errors for when your classes are misused?