Previous 1 2 3 4 Next 49 Replies Latest reply: Jun 19, 2012 4:07 PM by mark133
mark133 Level 1 Level 1

I'm not sure I'm getting this correctly, but is there a difference between a initializing a receiver with alloc/Init vs. using +(id)new 

 

Where does the class name argument fit into the +(id)new method?

 

In either case, once a new instance is returned, does that mean that during runtime the instance of the object will be where the command pointer goes next? And then that instance continues to be available during run until deallocated?

 

What if you want to have more than one instance of the class available during runtime? Is it better just to initialize one, use it, destroy it, and initialize another, etc, in rapid succession, or better to initialize a quantity of instances, if needed during runtime (if possible)?


iMac
Solved by etresoft on Jun 19, 2012 10:58 AM Solved

It's a long story.

 

In the beginning (yes, that far back), people wrote procedural programs. The main() function ran, read command-line inputs, read input from the screen or files, performed some operations, and then quit.

 

The modern application is a completely different beast. It is much closer to real-time programming. There really is no startup and shutdown that you can directly access. There is only an event loop, which you also can't (easily) directly access. At certain times, when the runtime feels that it is ready, it may try to call some delegate methods like awakeFromNib, applicationDidFinishLaunching, etc. Your apps sits and waits for those to be called to initialize itself. Initialization can be tricky because not all parts of the runtime system are available at different points in the initialization. When the program is running, it will handle all of the user interaction and perform any actions that you have setup.

 

If you are learning how to program, it is much, much better to start with procedural programs run from the Terminal on the command-line. That way you can learn about how variables and classes work. A modern iOS or MacOS X application is really a pretty advanced task.

Reply by HyperNova Software on Jun 18, 2012 8:35 AM Helpful

Create as many instances of a class that you need at the time you need them.

 

Depends entirely on your requirements.

Reply by HyperNova Software on Jun 18, 2012 8:41 AM Helpful

I've never used +(id)new.

 

I use "Class *instanceName = [[Class alloc]init];

All replies

Previous 1 2 3 4 Next