• 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: Dereferencing a pointer in ObjC?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dereferencing a pointer in ObjC?


  • Subject: Re: Dereferencing a pointer in ObjC?
  • From: Chris Hanson <email@hidden>
  • Date: Mon, 29 Jul 2002 02:48:23 -0500

At 1:27 AM -0600 7/29/02, Terry Simons wrote:
This may be a really stupid question, but how do I dereference a pointer in ObjectiveC?

Same way you would in C.

I have the following code:

if(@"Red" == [[myRadioMatrix selectedCell] title])
{
//do something
}

Now... I can't do this because @"Red" is an NSString, but [[myRadioMatrix selectedCell] title] is an NSString *.

No, @"Red" is also an instance of NSString (i.e. an NSString *). All objects in Objective-C are pointers; there is no such thing as a "stack object" in Objective-C.

As I told someone else within the last 24 hours, you don't want to compare objects using == because that will just test pointer equality. Use isEqualTo: or isEqualToString: (if you know both objects are instances of NSString) to compare objects.

Also, The above code is basically checking the name of the radio button in an NSMatrix to see which button is currently selected. Is there a better way to do such checks? It seems to me that the simplest way would be to grab the name of the radio button, because that's a known value to me.

You don't want to compare the name, because your application could be localized.

Well, if you used an NSLocalizedString, you could probably get away with it. You'd be better off comparing tag values, though. Tags are integers; they can be set in Interface Builder and retrieved by sending -tag to instances of NSControl. They can also be set by sending -setTag: of course.

-- Chris

--
Chris Hanson | Email: email@hidden
bDistributed.com, Inc. | Phone: +1-847-372-3955
Making Business Distributed | Fax: +1-847-589-3738
http://bdistributed.com/ | Personal Email: email@hidden
_______________________________________________
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:
    • NSOpenPanel question
      • From: Raymund Beyer <email@hidden>
References: 
 >Dereferencing a pointer in ObjC? (From: Terry Simons <email@hidden>)

  • Prev by Date: Re: Dereferencing a pointer in ObjC?
  • Next by Date: awakeFromNib and action question
  • Previous by thread: Re: Dereferencing a pointer in ObjC?
  • Next by thread: NSOpenPanel question
  • Index(es):
    • Date
    • Thread