Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tw002

macrumors newbie
Original poster
Feb 23, 2009
16
0
Hi.

I'm in the process of (trying) to learn Obj C/Cocoa, and I'm all together new to OOP.

I'm trying to write a simple app that will store to do's. At the moment, all I want it to do is to read data from input text fields (working) and on the press of the create button, instantiate a new todoItem object, with the data stored as instance variables. So essentially every to do item is an object.

My problem is, this all works, but only when there's just one object being instantiated.

For example:
When the 'create to do' button is pressed, an IBAction method runs this code:

Code:
todoItem *itemOne = [todoItem alloc] init];

then writes its ivars etc..

Obviously, if you press the button again, the exact same code is run, giving an error 'redefinition of itemOne'. Rather than doing this, I need for the object to be dynamically named, so each time the button is pressed objects are instantiated and named automatically eg. itemOne, itemTwo etc.

Is this possible? Perhaps an array of objects?

I hope you understood that longwinded description.

Thanks in advance, Thomas.
 
Hence the 'in the progress of learning'. Thanks anyway.

Then you need to learn the theory: basic statements then loops and conditionals then data structures. Once you know those in abstract terms start looking at Objective-C/Cocoa specific examples of them.

Trying to learn by coding before doing the above almost always ends in failure.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.