• 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: best way to test for NSString / NSCFString type of object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: best way to test for NSString / NSCFString type of object?


  • Subject: Re: best way to test for NSString / NSCFString type of object?
  • From: Daryn <email@hidden>
  • Date: Thu, 2 Oct 2003 19:49:25 -0500

NSString is merely the abstract class for a class cluster. What you really want to do is test if the class inherits from NSString:

if ([[array lastObject] isKindOfClass:[NSString class]]) { ... }

On Thursday, October 2, 2003, at 07:32 PM, Ben Dougall wrote:

i've got a method that sometimes returns an NSString other times other types of object. whatever's returned i put straight into an NSMutableArray. i want to keep adding to the array until there's an NSString, so i put this line in to test for that just after adding to the array:

if( [[[array lastObject] className] isEqual:@"NSString"] ) {
...

it never successfully detected a string. i printed out the object types to see what was going on and the NSStrings had unexpectedly turned into the class type NSCFString. changing the test to that then worked fine, but is that safe? will it always be NSCFString rather than NSString? what's the best way to make that test? and how come it's changed?

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.


Daryn
_______________________________________________
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.

References: 
 >best way to test for NSString / NSCFString type of object? (From: Ben Dougall <email@hidden>)

  • Prev by Date: Re: best way to test for NSString / NSCFString type of object?
  • Next by Date: Re: best way to test for NSString / NSCFString type of object?
  • Previous by thread: Re: best way to test for NSString / NSCFString type of object?
  • Next by thread: Re: best way to test for NSString / NSCFString type of object?
  • Index(es):
    • Date
    • Thread