• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Returning structs of NSStrings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Returning structs of NSStrings


  • Subject: Re: Returning structs of NSStrings
  • From: Ondra Cada <email@hidden>
  • Date: Thu, 25 Mar 2004 12:01:38 +0100

Michael,

On Thursday, Mar 25, 2004, at 11:26 Europe/Prague, Michael Becker wrote:

I've noticed that dealing with large structs of NSStrings can get really annoying ("copying" these structs can only be done via copying each NSString in them [right?]). So should I make all of these into classes, providing accessor methods? Or am I missing out on something again?

Depends on the actual task of course, but most probably, instead of structs you want to use dictionaries:

[mydict setObject:o forKey:@"whatever"]; // instead of mystruct.whatever=o
o=[mydict objectForKey:@"whatever"]; // instead of o=mystruct.whatever

perhaps even adding specific "accessors" of a kind

@implementation NSMutableDictionary (MyOwnData)
-whatever { return [self objectForKey:@"whatever"]; }
-(void)setWhatever:o { [self setObject:o forKey:@"whatever"]; }
@end

possibly even replacing nil by a NSNull if you ever need to store it.

In a vast majority of cases the speed penalty is completely negligible, whilst the convenience, robustness, and maintainability gain is *tremendous*.
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Returning structs of NSStrings
      • From: Michael Becker <email@hidden>
References: 
 >Re: Returning structs of NSStrings (From: Michael Becker <email@hidden>)

  • Prev by Date: Um... How do you rename a file?
  • Next by Date: Re: Um... How do you rename a file?
  • Previous by thread: Re: Returning structs of NSStrings
  • Next by thread: Re: Returning structs of NSStrings
  • Index(es):
    • Date
    • Thread