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, 01:25 PM   #10 (permalink)
p.witty
New Member
 
Join Date: Apr 2009
Posts: 4
Default

Look, suppose I have a "currentUser" instance of my User Model. I want to be able to access that specific "currentUser" instance anywhere in my app -- in every single controller.

As some people have pointed out, using the App Delegate seems to be a good way to do this -- and people use it this way in various examples and whatnot on the net -- but to some of us, this doesn't seem like an ideal solution.

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];

Or even more generically,

NSArray myUsers = [User findByName:@"Joe Bob"];

And it would return an array of users with the name Joe Bob (who exist in memory -- not persisted to the DB).

But we could take this approach a step further and bring it to persisted context. At this point the classes would be behaving more like we're in Ruby on Rails than anything else. 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"];

And then the class would do memory management -- pushing dirty objects back to the DB and clearing unchanged objects from memory when they are no longer used and when we get low memory warnings.

What do you folks think?

-Steve
p.witty is offline   Reply With Quote
 

» Advertisements
» Online Users: 688
23 members and 665 guests
ADY, dacapo, Dani77, Dattee, EvilOne, headkaze, HowEver, iamlexus, jakerocheleau, JasonR, jbro, jneiluj78, justin-UK, Keys, mapiko, mer10, MSP4444, Oral B, overlordhammer, Punkjumper, sandihf, smethorst, uptownben
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,744
Threads: 89,200
Posts: 380,559
Top Poster: BrianSlick (7,129)
Welcome to our newest member, Dani77
Powered by vBadvanced CMPS v3.1.0

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