Let me start by saying I **think** I understand why my first approach did not work, but am interested if my working approach is correct in concept.

Background.
As a **very long** detour from Hillegass's chapter 18 challenge, I am following along with mmalc's excellent series of Binding examples. Thus, now creating a table of 4 columns without bindings. (He uses 1 column, but I added a few).


In order to create the NSMutableDictionary object, which will be added to an NSDoc Array ivar, (which will be used by the datasource methods of a table) I have created a

Record Object with one ivar (  _record ( An NSMutableDictionary).)

which returns:

First approach: ( did **not** work)

-(id) init
{
      self = ....snip...usual code
       NSString * _name = @"John Doe";
       NSString *  _city
       ....snip...other string properties


      _record = [ NSMutableDictionary dictionaryWithObjectsAndKeys:
       _name, MDHNameKey,
       ....snip...
      nil;
    }
  return self;
}


As I learnt, self returns an empty object. ( If I understand it correctly, the local variables _name etc are no longer in scope once self is returned.)


Second approach.

Record Object with 4 ivars viz
_name
_city etc etc


Self now returns an object whose attributes are now, in the calling method ( the "AddRecord") used to create the NSMutableDictionary object and added "model" array, and the table populates as expected.


May I ask if this is the correct approach? ...or should one still try and aim to **return** a dictionary object to the calling method?

Thanks as always, in advance.







_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to