• 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: labelling some NSString objects, without making a new class?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: labelling some NSString objects, without making a new class?


  • Subject: Re: labelling some NSString objects, without making a new class?
  • From: Ben Dougall <email@hidden>
  • Date: Wed, 1 Oct 2003 23:41:18 +0100

(i sent this absolutely ages ago - no sign of it so..)

On Wednesday, October 1, 2003, at 04:33 pm, Alex Lock wrote:

On Wednesday, October 1, 2003, at 09:20 AM, Ben Dougall wrote:

rather than creating a new class that does nothing but simply wrap around an NSString giving a different identity from a normal NSString instance, is there a better, more efficient way of labelling NSString objects to enable distinguishing between instances of the normal NSString type and instances of the labelled NSString type? just seems a bit wasteful to do that with a new object type - that'll result in two objects per labelled object.

At runtime you wouldn't be creating "two objects"...

You'd be creating one object with your new properties + inheritance from parents.

When you create a (normal) NSString, it doesn't create an NSObject first it just creates an NSString. Likewise, if you were to instantiate a "myString" object, you would only be creating THAT object (with parent properties). This is the whole basis for object-oriented programming:)

but i'm not subclassing, and i don't think it'll be a good idea to either as it's an NSString which is a class cluster - best left unsubclassed. (would/could this be dealt with by categories by any chance? i've never used them. (they're probably no use here.))


Out of curiosity (and perhaps to offer some help) what is it that you're trying to accomplish where you'd need to be able to identify a string by anything other than variable name or array/dictionary location?

i'm reading in information that's split into lots of little bits and these little bits often easily and obviously correlate to various basic cocoa data objects. such as a string in the information -> NSString. it's now apparent that there are two different types of strings that i need to be able to differentiate between at a later point. right now i stick both types of string from the information into an NSString. from then on, at the moment, i am unable to differentiate between these two types of strings. i need to, when creating the string instances, be able to mark in some way one of the two types. i could easily make an object for this purpose, that just holds a pointer to an NSString, and that class that i just made would have it's own name so i'd easily be able to differentiate. one type i'd use this class that i just made, and the other type i'd use NSStrings as is. but for one of the two types of strings i'd have two objects rather than one which seems a bit wasteful.

......

answering my own q, i've just thought how to do this - a pretty simple and small solution: use a particular defining character in the first character space of the string as a label.

thanks, ben.
_______________________________________________
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.

  • Prev by Date: Automating a background picture in a DMG
  • Next by Date: Re: miniaturized files in Dock
  • Previous by thread: Re: Automating a background picture in a DMG
  • Next by thread: Re: miniaturized files in Dock
  • Index(es):
    • Date
    • Thread