Last active
December 18, 2015 19:08
-
-
Save uzzu/5830325 to your computer and use it in GitHub Desktop.
reflection method ?
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
#import <SenTestingKit/SenTestingKit.h> | |
@interface UZUPracticeTest : SenTestCase | |
@end |
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
#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