Wednesday, February 19, 2014

Determining an Objective-C Class Type

// STRING TO NUMBER  

   NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
    [f setNumberStyle:NSNumberFormatterDecimalStyle];

if ([[myDict valueForKey:@"faxSent"] isKindOfClass:[NSString class]])
    {
        NSString* hasFaxBeenSent = [myDict valueForKey:@"faxSent"];
        hasFaxBeenSentNumber = [f numberFromString:hasFaxBeenSent];
    }
    else if ([[myDict valueForKey:@"faxSent"] isKindOfClass:[NSNumber class]])
    {
        hasFaxBeenSentNumber = [myDict valueForKey:@"faxSent"];

    }

// NUMBER TO STRING

    if ([[myDict objectForKey:@"emailAddressExists"] isKindOfClass:[NSString class]])
    {
        emailAddressExists = [myDict objectForKey:@"emailAddressExists"];
        
    }
    else if ([[myDict objectForKey:@"emailAddressExists"] isKindOfClass:[NSNumber class]])
    {
        emailAddressExistsNumber = [myDict valueForKey:@"emailAddressExists"];
        emailAddressExists = [emailAddressExistsNumber stringValue];
    

    }

No comments:

Post a Comment