small medium large xlarge

Generic-user-small
03 Dec 2009, 17:18
Peter Battaglia (28 posts)

Hi Bill-

One thing that would be nice in the next addition of screencasts is to touch on the idea of Class Variables. I’ve had a hard time grasping Class Level variables in Objective-C and no one seems to talk about it.

I added a post to the “Programming Cocoa” section (http://forums.pragprog.com/forums/86/topics/3722) as there is no discussion in this book (that I have found) discussing how to declare and use read-only class level properties.

If you know of any tutorials, or have some feedback on the subject, I would love to hear it.

Thanks!

Biopic_100x100_pragsmall
03 Dec 2009, 21:21
Bill Dudney (917 posts)

Hi Peter,

No one talks about it because its not possible :)

To make this work people do various things. The approach I’ve seen most often used is something like the way that UIApplication’s sharedApplication instance works. There is a static variable in the UIApplication.m that is set only in the sharedApplication method.

Google around for ‘singleton’ in Obj-C.

Good luck!

Generic-user-small
03 Dec 2009, 21:31
Peter Battaglia (28 posts)

Hi Bill-

Thanks for the response, I was kind of getting that feeling based on what I was reading.

I’ll check out the singleton pattern in obj-c and see if that works.

I tried going about it by creating “readonly” instance variables, then trying to set them in the initialization method, but of course that was not working.

So just to clarify, there’s no way to create “readonly” properties in a class that can be read when an instance of the class is created?

Thanks again for the response, -peter

You must be logged in to comment