Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-21-2009, 06:17 PM   #15 (permalink)
eddietr
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Quote:
Originally Posted by p.witty View Post
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.

Last edited by eddietr; 04-21-2009 at 06:21 PM.
eddietr is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,746
Threads: 89,202
Posts: 380,573
Top Poster: BrianSlick (7,129)
Welcome to our newest member, raKinesic
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:52 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.