RE: Trying to understand -- please help...

2008-05-22 Thread Caleb Strockbine
On May 21, 2008, at 2:39 PM, Johnny Lundy [EMAIL PROTECTED] wrote: Here's why the OP was not aware of the behavior of an NSArray class method: Here's the verbatim documentation for +arrayWithObjects: [...deleted...] See? Not a word about autoreleasing anything, or having to retain the

Re: Trying to understand -- please help...

2008-05-22 Thread Greg Titus
On May 21, 2008, at 12:37 PM, Johnny Lundy wrote: This is just one example of that little tidbit that is always left out of these references by Apple. It seems to be the .O. for some reason. The tidbit isn't some extraneous bell or whistle; it's always something fundamental. They can't

Re: Trying to understand -- please help...

2008-05-22 Thread Joseph Kelly
If you've got complaints or suggestions for Documentation, then go to http://bugreport.apple.com/ and file a bug. Apple seems intent on working with these kinds of suggestions, esp. if they help newcomers transition to the platform. Sincerely, Joe K.

Re: Trying to understand -- please help...

2008-05-22 Thread Andy Lee
On May 22, 2008, at 5:13 PM, Johnny Lundy wrote: My point in using that class reference was simply to show how someone could follow the manual and still have his code not work. Actually, the introductory documentation never actually says that the convenience constructors always return

Re: Trying to understand -- please help...

2008-05-21 Thread Torsten Curdt
You probably want to use a NSArrayController and bind the combo box to that. When you hit the buttons you change the array through the controller. HTH ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or

Re: Trying to understand -- please help...

2008-05-21 Thread Vijay Malhan
You are not retaining the autoreleased array in your constructor. You are over-riding the first initialization of your array(which is a leak) while you are initializing with arrayWithObjects: call. You can remove this line completely cityArray = [[NSArray alloc] init]; and do a retain on

Re: Trying to understand -- please help...

2008-05-21 Thread Paul Bailey
What you're doing here is allocating an empty array, and then setting the pointer of your instance variable to a new array, created with the arrayWithObjects message. An array returned by this message is autoreleased, so at the end of your init method, it's being released. All these type of

Re: Trying to understand -- please help...

2008-05-21 Thread Hank Heijink (Mailinglists)
On May 21, 2008, at 12:05 PM, john darnell wrote: - (id) init { cityArray = [[NSArray alloc] init]; NSString *c0 = @New York; //Ten NSString objects created here ... NSString *c9 = @Virginia Beach; cityArray = [NSArray arrayWithObjects: c0, ...c9, nil]; return self; } Here's

RE: Trying to understand -- please help...

2008-05-21 Thread john darnell
: Re: Trying to understand -- please help... To: john darnell [EMAIL PROTECTED] Ok, I'm somewhat of a beginner myself, but here's what I see. First off: Your array is being 'emptied' because [NSArray arrayWithObjects:] returns an autoreleased array. You should retain this like so [[NSArray

Re: Trying to understand -- please help...

2008-05-21 Thread João Pavão
Also, since the initializer methods of the superclasses aren't invoked automatically for you, you should code your initializers using a pattern along the lines of: - init { if (self = [super init]) { // ... initialization statements for the instance variables of

Re: Trying to understand -- please help...

2008-05-21 Thread Gérard Iglesias
Well Something like this is standard : - (id)init { if (!(self = [super init])) return nil; cityArray = [[NSArray alloc] initWithObjects: @New York ..., nil]; return self; } would

RE: Trying to understand -- please help...

2008-05-21 Thread john darnell
@lists.apple.com Subject: Re: Trying to understand -- please help... Well Something like this is standard : - (id)init { if (!(self = [super init])) return nil; cityArray = [[NSArray alloc] initWithObjects: @New York

Re: Trying to understand -- please help...

2008-05-21 Thread Gérard Iglesias
with an empty NSArray (not very useful, since you can't add items to an NSArray). Then, you leak that allocated memory by setting cityArray to an autoreleased NSArray In fact it is not leaking, it is just creating an object for nothing, it will be released by the autorelease pool, than no

Re: Trying to understand -- please help...

2008-05-21 Thread Clark Cox
On Wed, May 21, 2008 at 9:49 AM, Gérard Iglesias [EMAIL PROTECTED] wrote: with an empty NSArray (not very useful, since you can't add items to an NSArray). Then, you leak that allocated memory by setting cityArray to an autoreleased NSArray In fact it is not leaking, it is just creating an

Re: Trying to understand -- please help...

2008-05-21 Thread Shawn Erickson
On Wed, May 21, 2008 at 9:47 AM, Peter Hudson [EMAIL PROTECTED] wrote: The line of code [NSArray arrayWithObjects: c0, ...c9, nil]; produces an array all right - but as you have used a class initializer, it will auto release when you return from the method where it was created. They are

Re: Trying to understand -- please help...

2008-05-21 Thread Bill Bumgarner
On May 21, 2008, at 9:49 AM, Gérard Iglesias wrote: with an empty NSArray (not very useful, since you can't add items to an NSArray). Then, you leak that allocated memory by setting cityArray to an autoreleased NSArray In fact it is not leaking, it is just creating an object for nothing,

Re: Trying to understand -- please help...

2008-05-21 Thread Hank Heijink (Mailinglists)
On May 21, 2008, at 12:49 PM, Gérard Iglesias wrote: with an empty NSArray (not very useful, since you can't add items to an NSArray). Then, you leak that allocated memory by setting cityArray to an autoreleased NSArray In fact it is not leaking, it is just creating an object for

Re: Trying to understand -- please help...

2008-05-21 Thread Shawn Erickson
You probably want to use a NSArrayController and bind the combo box to that. When you hit the buttons you change the array through the controller. Folks please don't point someone at things like NSArrayController when they are just getting started. Using controller layer / bindings can make a

Re: Trying to understand -- please help...

2008-05-21 Thread Sherm Pendley
On Wed, May 21, 2008 at 12:47 PM, Peter Hudson [EMAIL PROTECTED] wrote: The line of code [NSArray arrayWithObjects: c0, ...c9, nil]; produces an array all right - but as you have used a class initializer, it will auto release when you return from the method where it was created. No,

Re: Trying to understand -- please help...

2008-05-21 Thread Ilan Volow
You also want to add a dealloc method to your class that releases cityArray, something like: - (void)dealloc { [cityArray release]; [super dealloc]; } -- Ilan On May 21, 2008, at 12:05 PM, john darnell wrote: Hello Everyone: I decided that it was time for a play period

Re: Trying to understand -- please help...

2008-05-21 Thread Shawn Erickson
On Wed, May 21, 2008 at 10:11 AM, Gérard Iglesias [EMAIL PROTECTED] wrote: Or am I missing something ? Yes :) You are misreading what he typed I inlined what he typed with the code... - (id) init { // First, you allocate and initialize the cityArray with an empty NSArray (not very useful,

Re: Trying to understand -- please help...

2008-05-21 Thread I. Savant
Any initialiser with a + in front of it returns an autoreleased object ACK! NO! A *method* with a + is a class method, whether it returns an autoreleased object or nothing at all. Class methods that return autoreleased objects are for convenience, but not all of them do. Consider

Re: Trying to understand -- please help...

2008-05-21 Thread I. Savant
Consider +(void)initialize ... also, *none* of them are initializers by implication because they're class methods. Sorry, these two sentences seem to be contradictory. Let me clarify: +initialize is used to initialize the *class*. No class methods are *instance* initializers or have anything

Re: Trying to understand -- please help...

2008-05-21 Thread Shawn Erickson
Nonsense. Nonsense again. Yet more nonsense. Lets avoid this kind of tone in emails on this list... correct, clarify, explain, etc. and leave it at that. -Shawn ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin

Re: Trying to understand -- please help...

2008-05-21 Thread Vijay Malhan
On 21-May-08, at 11:37 PM, I. Savant wrote: Consider +(void)initialize ... also, *none* of them are initializers by implication because they're class methods. Sorry, these two sentences seem to be contradictory. Let me clarify: +initialize is used to initialize the *class*. No class

Re: Trying to understand -- please help...

2008-05-21 Thread Bill Bumgarner
On May 21, 2008, at 11:35 AM, Johnny Lundy wrote: Seriously, read that assuming you wanted to try out the NSArray class and tell me how it accomplishes its purpose of documenting what it is intended to document. It doesn't. And this pattern is repeated over and over in just about every one

Re: Trying to understand -- please help...

2008-05-21 Thread Shawn Erickson
On Wed, May 21, 2008 at 11:35 AM, Johnny Lundy [EMAIL PROTECTED] wrote: Here's why the OP was not aware of the behavior of an NSArray class method: Here's the verbatim documentation for +arrayWithObjects: arrayWithObjects: Creates and returns an array containing the objects in the argument

Re: Trying to understand -- please help...

2008-05-21 Thread I. Savant
What exactly do you mean by initializing the *class*? what exactly is initialized with +initialize() method? When exactly this method gets called? Read the documentation!

Re: Trying to understand -- please help...

2008-05-21 Thread Shawn Erickson
On Wed, May 21, 2008 at 11:47 AM, Vijay Malhan [EMAIL PROTECTED] wrote: What exactly do you mean by initializing the *class*? what exactly is initialized with +initialize() method? When exactly this method gets called? Look for the subsection titles Initializing a Class Object

+initialize (was Re: Trying to understand -- please help...)

2008-05-21 Thread Jason Stephenson
Vijay Malhan wrote: What exactly do you mean by initializing the *class*? what exactly is initialized with +initialize() method? When exactly this method gets called? If you are at all familiar with Java, this is the same thing as a static initializer. It sets up data required

Re: Trying to understand -- please help...

2008-05-21 Thread Ilan Volow
The most common (albeit deprecated) example that immediately comes to my mind is here: http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueObserving_Protocol/DeprecationAppendix/AppendixADeprecatedAPI.html#/ /apple_ref/occ/clm/NSObject/

Re: Trying to understand -- please help...

2008-05-21 Thread I. Savant
Pretty soon, the documentation is going to be 80% repetition and 20% actual unique-to-the-class content. snip I understand the frustration initially experienced by reading, say, the docs to NSArray and not having every last detail spelled out. At the same time, most of the details are

Re: Trying to understand -- please help...

2008-05-21 Thread Michael Vannorsdel
You troubles are all in this method and how you handle cityArray. First you don't need to alloc and init a new array for cityArray as [NSArray arrayWithObjects: c0, ...c9, nil] gives you a new one already with the objects you specified. Another thing you should watch for is there's an

Re: Trying to understand -- please help...

2008-05-21 Thread Vijay Malhan
Thanks for the pointers to the documentation. This is sample snippet from the documentation. @implementation MyClass + (void)initialize { if ( self == [MyClass class] ) { /* put initialization code here */ } } If I'm not wrong self equivalent of this which points to an

Re: Trying to understand -- please help...

2008-05-21 Thread Shawn Erickson
On Wed, May 21, 2008 at 12:14 PM, Vijay Malhan [EMAIL PROTECTED] wrote: Thanks for the pointers to the documentation. This is sample snippet from the documentation. @implementation MyClass + (void)initialize { if ( self == [MyClass class] ) { /* put initialization code here

Re: Trying to understand -- please help...

2008-05-21 Thread Jeff LaMarche
On May 21, 2008, at 3:37 PM, Johnny Lundy wrote: I submit that any experienced programmer looking up and turning to a page entitled NSArray Class Reference would expect that a behavior of the class that results in one's created object being deallocated out from under him would be

Re: Trying to understand -- please help...

2008-05-21 Thread Sherm Pendley
On Wed, May 21, 2008 at 2:48 PM, Bill Bumgarner [EMAIL PROTECTED] wrote: I have taught/mentored/managed/reviewed/interviewed literally hundreds of Cocoa programmers over the past two decades (counting Cocoa's NeXT produced predecessors). My experience has been that the most successful Cocoa

Re: Trying to understand -- please help...

2008-05-21 Thread Uli Kusterer
Am 21.05.2008 um 18:34 schrieb Gérard Iglesias: In fact in its original case, there would be a crash, because cityArray would point to a trashed pointer... I don't understand why it is not crashing. Well, it's not a trashed pointer. The memory has been alloced (and self is set already),

Re: Trying to understand -- please help...

2008-05-21 Thread Sherm Pendley
On Wed, May 21, 2008 at 3:37 PM, Johnny Lundy [EMAIL PROTECTED] wrote: I submit that any experienced programmer looking up and turning to a page entitled NSArray Class Reference would expect that a behavior of the class that results in one's created object being deallocated out from under

Re: Trying to understand -- please help...

2008-05-21 Thread Uli Kusterer
Am 21.05.2008 um 18:47 schrieb Peter Hudson: Any initialiser with a + in front of it returns an autoreleased object NO! Several mistakes in this sentence: 1) + simply means that it is a method of the class, not of individual instances. It has NOTHING to do with whether the result is

Re: Trying to understand -- please help...

2008-05-21 Thread Sherm Pendley
On Wed, May 21, 2008 at 3:14 PM, Vijay Malhan [EMAIL PROTECTED] wrote: Thanks for the pointers to the documentation. This is sample snippet from the documentation. @implementation MyClass + (void)initialize { if ( self == [MyClass class] ) { /* put initialization code here

Re: Trying to understand -- please help...

2008-05-21 Thread Christopher Nebel
On May 21, 2008, at 10:36 AM, Sherm Pendley wrote: [Objects] are simply released when the autorelease pool they are created in is released - which you can treat as occurring at the end of the method in which the init occurs. Nonsense again. The autorelease pool is emptied at the end of

Re: Trying to understand -- please help...

2008-05-21 Thread Hamish Allan
On Wed, May 21, 2008 at 7:35 PM, Johnny Lundy [EMAIL PROTECTED] wrote: All it would take is a single sentence under the Class Methods header, to say that these methods autorelease the returned object (AND that such autoreleasing means that the object will be deallocated if the method in which

Re: Trying to understand -- please help...

2008-05-21 Thread Sherm Pendley
On Wed, May 21, 2008 at 1:32 PM, Shawn Erickson [EMAIL PROTECTED] wrote: Folks please don't point someone at things like NSArrayController when they are just getting started. Using controller layer / bindings can make a lot of things easier and cleaner code (heck no code) but it really

Re: Trying to understand -- please help...

2008-05-21 Thread Ken Thomases
On May 21, 2008, at 1:35 PM, Johnny Lundy wrote: All it would take is a single sentence under the Class Methods header, to say that these methods autorelease the returned object (AND that such autoreleasing means that the object will be deallocated if the method in which it was created

Re: Trying to understand -- please help...

2008-05-21 Thread Sherm Pendley
On Wed, May 21, 2008 at 5:06 PM, Christopher Nebel [EMAIL PROTECTED] wrote: On May 21, 2008, at 10:36 AM, Sherm Pendley wrote: [Objects] are simply released when the autorelease pool they are created in is released - which you can treat as occurring at the end of the method in which the

Re: Trying to understand -- please help...

2008-05-21 Thread Andy Lee
On May 21, 2008, at 2:45 PM, Shawn Erickson wrote: Nonsense. Nonsense again. Yet more nonsense. Lets avoid this kind of tone in emails on this list... Yes, please. --Andy correct, clarify, explain, etc. and leave it at that. -Shawn ___

Re: Trying to understand -- please help...

2008-05-21 Thread Jens Alfke
On 21 May '08, at 12:37 PM, Johnny Lundy wrote: I submit that any experienced programmer looking up and turning to a page entitled NSArray Class Reference would expect that a behavior of the class that results in one's created object being deallocated out from under him would be

Re: Trying to understand -- please help...

2008-05-21 Thread Jens Alfke
On 21 May '08, at 12:14 PM, Vijay Malhan wrote: If I'm not wrong self equivalent of this which points to an instance var. And it is initialized in - init (instance)method. And if it fails to initialize, it's nil. So does self even exist when + initialize is called. This is a class

Re: Trying to understand -- please help...

2008-05-21 Thread Jens Alfke
On 21 May '08, at 11:35 AM, Johnny Lundy wrote: See? Not a word about autoreleasing anything, or having to retain the returned array. Nada. It also didn't spell out that: the return value is a pointer, pointers are 4 or 8 bytes large, the pointer value zero is special and is named nil,

Re: Trying to understand -- please help...

2008-05-21 Thread Michael Vannorsdel
Would be like a cookbook including instructions on how to operate an oven and use a knife to cut vegetables in every single recipe. I think most would find that pretty redundant and diluting, especially when the preface covers these topics in detail. On May 21, 2008, at 8:37 PM, Jens