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, 12: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
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,136
Threads: 38,911
Posts: 170,717
Top Poster: smasher (2,565)
Welcome to our newest member, cye
Powered by vBadvanced CMPS v3.1.0

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