Created
August 3, 2012 00:16
-
-
Save christianroman/3242465 to your computer and use it in GitHub Desktop.
Switch Object in Objective-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOOL switchObject(id anObject, ...) | |
{ | |
va_list args; | |
va_start(args, anObject); | |
id value = nil; | |
BOOL matchFound = NO; | |
while ( (value = va_arg(args,id)) ) | |
{ | |
void (^block)(void) = va_arg(args,id); | |
if ([anObject isEqual:value]) | |
{ | |
block(); | |
matchFound = YES; | |
break; | |
} | |
} | |
va_end(args); | |
return matchFound; | |
} | |
/* Usage */ | |
switchObject(popoverController, | |
sexoPopover, ^{ | |
[sexo setPlaceholder:[sexoArray objectAtIndex:sexoSelected]]; | |
}, | |
estadoFamiliarPopover, ^{ | |
[estadoFamiliar setPlaceholder:[estadoFamiliarArray objectAtIndex:estadoFamiliarSelected]]; | |
}, | |
procedenciaFondosPopover, ^{ | |
[procedenciaFondos setPlaceholder:[procedenciaFondosArray objectAtIndex:procedenciaFondosSelected]]; | |
}, | |
usoFondosPopover, ^{ | |
[usoFondos setPlaceholder:[usoFondosArray objectAtIndex:usoFondosSelected]]; | |
}, | |
profesionPopover, ^{ | |
[profesion setPlaceholder:[profesionArray objectAtIndex:profesionSelected]]; | |
}, | |
nil); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment