Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Obj-C 101...

Obj-C 101...
Thread Tools
Mac Enthusiast
Join Date: Mar 2001
Location: North America
Status: Offline
Reply With Quote
Apr 10, 2001, 11:12 PM
 
Okay please excuse my simple questions:

1) In C++ you can initialize member values inside the constructors implementation using a initialization list, like so (taken from "Effective C++" by Scott Meyers):
Code:
NamedData::NamedData(const String& initName, void *dataPtr) : name(initname), data(dataptr) {...}
This allows member variables to get init'ed. I think Obj-C doesn't have constructors, but can you do this kind of thing?

AND...

How are timed events done easily? Is there a wait() function I can use or do I have to use NSTimer and create an Invocation using self as the id?

thanks for reading!
-John
My life is my argument. --Albert Schweitzer
     
Professional Poster
Join Date: Jan 2000
Status: Offline
Reply With Quote
Apr 10, 2001, 11:56 PM
 
It has what's called the "init" function. Often in the init you'll call the init of the super class and then init your stuff for the sub class.
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Apr 11, 2001, 10:14 AM
 
Like Scott_H said, init is the default constructor. All objects support init. If you want to initialize something with some data, however, you would usually called something like:

[[MyObject alloc] initWithString:@"Moo" lifespan:4];

NSTimers don't lock up your app, like sleep(int) would. You can also specify if the timer repeats.

[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:5]];

Will lock up the current thread for 5 seconds, then proceed to the next line.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Apr 11, 2001, 01:02 PM
 
The syntax for an init function is like this:

- (id)init {
[super init];

<<specific initialisation stuff>>

return self;
}

You must put super init and return self in otherwise it won't work properly, I don't think.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:02 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2