Hi guys,
Is there a way in Objective-C to check if a value is of a certain data type? For example:
Say I have a value a user enters and it could be a number or a char, and I want to ensure its one or the other, is there an easy way to do this? Obviously the below won't work but is there any way to do this that is just as simple?
//example
char myVar;
if(myVar != char data type)
I can think of a work around using C's atoi function but I'd rather not do it that way if there is a more elegant solution.
EDIT: Well, I learned something new today. I NEVER knew about the isdigit, isalpha, and isalnum operators. How I never knew about them I don't know but they work like a charm in this situation. I was just about to write a custom function using atoi too.
If anyone is reading this and is unfamiliar with programming here is how it works:
Same goes for the other operators.
Is there a way in Objective-C to check if a value is of a certain data type? For example:
Say I have a value a user enters and it could be a number or a char, and I want to ensure its one or the other, is there an easy way to do this? Obviously the below won't work but is there any way to do this that is just as simple?
//example
char myVar;
if(myVar != char data type)
I can think of a work around using C's atoi function but I'd rather not do it that way if there is a more elegant solution.
EDIT: Well, I learned something new today. I NEVER knew about the isdigit, isalpha, and isalnum operators. How I never knew about them I don't know but they work like a charm in this situation. I was just about to write a custom function using atoi too.
If anyone is reading this and is unfamiliar with programming here is how it works:
Code:
int myVar = 5;
if(isdigit(myVar))
NSLog(@"This is a variable");
Same goes for the other operators.
Last edited: