Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-21-2009, 05: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 05:21 PM.
eddietr is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,370
Threads: 39,163
Posts: 171,679
Top Poster: smasher (2,579)
Welcome to our newest member, Giga
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:03 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.