small medium large xlarge

14 Jun 2009, 01:44
Greg Borenstein (3 posts)

I’ve just worked through exercise 7.9: creating and using the initWithName method to add a initializer with argument to the HelloWorld class. Before looking at the solution, I wrote and got working my version which included everything in your solution besides the declaration of initWithName in HelloWorld.h. My code worked successfully without this declaration and no differently when it was added. I was wondering why this is – I’d assumed from part of your earlier discussion of init methods that as long as the method names started with “init” this would be the behaviour and so I was surprised to see you declare the custom initWithName method.

14 Jun 2009, 01:48
Greg Borenstein (3 posts)

Also, in the explanation of that solution, you mention that we need to retain the NSString passed-in as the name, but then you don’t indicate when it should be released.

24 Jul 2009, 13:59
Daniel H Steinberg (97 posts)

Thanks I fixed the text to indicate the release happens in dealloc. I declare methods that I want to be part of the public contract. You can call any method you implement (whether it’s in the header or not). You will, however, sometimes get a compiler warning that that object may not respond to the method you’re calling.

You must be logged in to comment