• 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: String Comparison and return values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String Comparison and return values


  • Subject: Re: String Comparison and return values
  • From: Kirk Kerekes <email@hidden>
  • Date: Tue, 26 May 2009 11:56:59 -0500

Consider the pattern:

[[thing description] isEqualToString: someString];

All objects will return a string for description. Whether it is meaningful in your terms is a whole other issue.

NSNumber will return a sensible numeric string.
NSString will return itself.

Generally, property-list objects (other than NSData) will return something generically useful in response to -description.

Note the NSStringFrom... functions for converting points, ranges, etc into strings and back again.

It is a good discipline to stick to property list objects for files when reasonable.



Also note that -[NSString rangeOfString:options] can be wrapped in a category on NSString to provide a handy -[NSString compare].

@implementation NSString (contains)

- (BOOL) contains:(NSString *) s
{ // loose compare
return [self rangeOfString: s options: NSCaseInsensitiveSearch].location != NSNotFound;
}


- (BOOL) containsPrecisely:(NSString *) s
{ // exact compare
return [self rangeOfString: s options: NSLiteralSearch].location != NSNotFound;
}


@end

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: String Comparison and return values
      • From: Shawn Erickson <email@hidden>
  • Prev by Date: Re: Displaying a number with Quartz
  • Next by Date: Re: Displaying a number with Quartz
  • Previous by thread: Re: String Comparison and return values
  • Next by thread: Re: String Comparison and return values
  • Index(es):
    • Date
    • Thread