Created
May 23, 2011 10:21
-
-
Save honjo2/986507 to your computer and use it in GitHub Desktop.
[Objective-C] プロトコル
This file contains hidden or 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 <Foundation/Foundation.h> | |
#import "MapDelegate.h" | |
@interface LightMapDelegate : NSObject <MapDelegate> { | |
} | |
@end |
This file contains hidden or 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 "LightMapDelegate.h" | |
@implementation LightMapDelegate | |
-(int)getMaxZoomLevel { | |
return 12; | |
} | |
@end |
This file contains hidden or 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 <UIKit/UIKit.h> | |
#import "Map.h" | |
#import "LightMapDelegate.h" | |
int main(int argc, char *argv[]) { | |
id<MapDelegate> delegate = [[LightMapDelegate alloc] init]; | |
Map *map = [[Map alloc] initWithMapDelegate:delegate]; | |
NSString * maxLevelString = [map getMaxLevelString]; | |
NSLog(maxLevelString); | |
} |
This file contains hidden or 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 <Foundation/Foundation.h> | |
#import "MapDelegate.h" | |
@interface Map : NSObject { | |
id delegate; | |
} | |
@property(assign) id<MapDelegate> delegate; | |
-(id)initWithMapDelegate:(id <MapDelegate>)_delegate; | |
-(NSString *)getMaxLevelString; | |
@end |
This file contains hidden or 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 "Map.h" | |
#import "MapDelegate.h" | |
@implementation Map | |
@synthesize delegate; | |
-(id)initWithMapDelegate:(id <MapDelegate>)_delegate { | |
self = [super init]; | |
if (self != nil) { | |
delegate = _delegate; | |
} | |
return self; | |
} | |
-(NSString *)getMaxLevelString { | |
int level = [delegate getMaxZoomLevel]; | |
NSString *ret = [NSString stringWithFormat:@"最大ズームレベルは%dです。", level]; | |
return ret; | |
} | |
@end |
This file contains hidden or 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 <UIKit/UIKit.h> | |
@protocol MapDelegate | |
@required | |
-(int)getMaxZoomLevel; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment