Skip to content

Instantly share code, notes, and snippets.

@uzzu
Last active December 18, 2015 19:08
Show Gist options
  • Save uzzu/5830325 to your computer and use it in GitHub Desktop.
Save uzzu/5830325 to your computer and use it in GitHub Desktop.
reflection method ?
#import <SenTestingKit/SenTestingKit.h>
@interface UZUPracticeTest : SenTestCase
@end
#import "UZUPracticeTest.h"
@implementation UZUPracticeTest
- (void)setUp
{
[super setUp];
// Set-up code here.
}
- (void)tearDown
{
// Tear-down code here.
[super tearDown];
}
- (void)testExample
{
NSString *expected = [NSString stringWithFormat:@"hogehoge"];
NSDictionary *methods = [[[NSDictionary alloc] initWithObjectsAndKeys:
[NSValue valueWithPointer:@selector(hogehoge)], @"hogehoge",
[NSValue valueWithPointer:@selector(fugafuga)], @"fugafuga",
[NSValue valueWithPointer:@selector(piyopiyo)], @"piyopiyo",
nil] autorelease];
SEL method = [[methods valueForKey:@"hogehoge"] pointerValue];
NSString *actual = (NSString *) [self performSelector:(method)];
STAssertTrue([actual isEqualToString:expected], @"Reflection");
}
- (NSString *)hogehoge
{
return [NSString stringWithFormat: @"hogehoge"];
}
- (NSString *)fugafuga
{
return [NSString stringWithFormat: @"fugafuga"];
}
- (NSString *)piyopiyo
{
return [NSString stringWithFormat:@"piyopiyo"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment