• 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: Comparing two object classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing two object classes


  • Subject: Re: Comparing two object classes
  • From: Tito Ciuro <email@hidden>
  • Date: Fri, 1 Jul 2005 00:11:50 -0400

Hi Sherm,

Thanks for the help.

I oversimplified the problem, so the solution you propose doesn't work. Here's why:

- (BOOL)verifyParameters:(NSDictionary*)info forMethod:(NSString*) methodName
{
NSArray *someParams = [[info objectForKey:MyParamsKey]allKeys];
BOOL paramsAreFine = NO;


if ([someParams count]) {
NSString *bundlePath = [[NSBundle bundleForClass:[self class]]bundlePath];
NSString *infoPlistPath = [NSString stringWithFormat:@"%@/ Contents/Info.plist", bundlePath];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:infoPlistPath];
NSDictionary *paramsInfo = [[[tempDict objectForKey:MyParamsKey];


        if (paramsInfo) {
            int i, count = [someParams count];

            paramsAreFine = YES;

for (i = 0; i < count; i++) {
id passedObject = [someParams objectAtIndex:i];
Class paramOriginalType = [[paramsInfo objectForKey:object]class];


                if (![passedObject isKindOfClass:paramOriginalType]) {
                    paramsAreFine = NO;
                    break;
                }
            }
            [tempDict release];
        }
    }

    return paramsAreFine;
}

I'm trying to make this method a generic datatype verification method. Any ideas how to make this work?

Thanks again,

-- Tito

On 30/06/2005, at 23:54, Sherm Pendley wrote:

On Jun 30, 2005, at 11:42 PM, Tito Ciuro wrote:


A method receives an object of type id. I want to make sure that the object is a string, so I'm using isKindOfClass. The problem is that sometimes the object is a NSConstantString and other times a NSCFString, so when the object passed is NSConstantString, isKindOfClass returns NO. Since both objects are strings, what test/comparison would return YES?


Both of those should descend from NSString, so I'd try:

if ([aString isKindOfClass:[NSString class]]) {
    // Yep, it's a string
}

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Comparing two object classes (From: Tito Ciuro <email@hidden>)
 >Re: Comparing two object classes (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: Comparing two object classes
  • Next by Date: NSHTTPCookieStorage doesn't provide the most current set of cookies.
  • Previous by thread: Re: Comparing two object classes
  • Next by thread: NSHTTPCookieStorage doesn't provide the most current set of cookies.
  • Index(es):
    • Date
    • Thread