Quote:
Originally Posted by p.witty
You mind sharing proper syntax for this? Wouldn't I just put it above the implementation?
static User currentUser;
@implementation MyViewController
|
Well, the static var would have to be a pointer to User. And you should create a class method (an accessor really) that creates the actual user object as needed. Remember, you can't actually create/load the user object in static scope.
Something like this:
Code:
+ (User*) currentUser
{
@synchronized(self) {
if (currentUser==nil)
// set up the user, find her, whatever
}
}
return currentUser;
}
+ (void) setCurrentUser: (User*) currentUser{
// if this is new user, release the old one and retain the new one
// assign it to the static var
}
Quote:
|
So how is this different from a class var?
|
Well, true class variables in other languages allow you to control the scope of that class and give you setters and accessors at the class level. But, again, it's not a huge deal. You can easily write this yourself.
Quote:
So have you implemented something like this on an iphone project? It sounds like a lot of work, and something that would be worthwhile to make *very* generic (as in, a super class I could inherit from to gain this functionality for any model) and sharing with the open source community.
|
Yep, can't do that legally now. But that would be a nice project. It's not a huge amount of work, but it is work to make it generic enough to actually be useful to other developers. Would you help with it?
Quote:
|
Of course, with the release of 3.0, we'll have CoreData, so that might make this sort of thing redundant.
|
In my testing, Core Data doesn't exactly address the issues we faced. But I can't get more into that without violating two different NDAs.

Maybe something to talk about later on, or it could be part of an open source solution to the general problem.