Quote:
Originally Posted by p.witty
An idea I've had -- but have not yet tried -- is to put these instances into appropriate static class vars. That is, to make instance-aware classes, so I can do something like this:
User currentUser = [User currentUser];
|
Yeah, so that's the classic singleton pattern, with access through a class method. Only issue is you can't have an actual class var in ObjC, so you have use global variables instead. Not a huge deal.
Quote:
Or even more generically,
NSArray myUsers = [User findByName:@"Joe Bob"];
|
So that's just a static method that would find instances as needed. With the "class variable" in this case being an array of model instances. So it's a little different, but still would work nicely.
Quote:
I'm not sure whether it would be better to have something which would differentiate between in-memory models and in-db models:
[User findInMemByName:@"Joe Bob"];
[User findInDbByName:@"Joe Bob"];
Or if it would be better to make it generic:
[User findByName:@"Joe Bob"];
|
So the latter ("generic", as you called it) approach is how I would generally do this. But it all depends on your project of course.