Created
October 30, 2012 22:05
-
-
Save ChrisRisner/3983381 to your computer and use it in GitHub Desktop.
iOS Day 10
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
@interface AppDelegate : UIResponder <UIApplicationDelegate> | |
@property (strong, nonatomic) UIWindow *window; | |
@property (strong, nonatomic) NSString *info; | |
@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
@implementation AppDelegate | |
-(void)doSomethingWithString:(NSString*)parameter { | |
self.info = parameter; | |
} | |
-(NSString*)getInfo { | |
return self.info; | |
} |
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
@interface AppDelegate : UIResponder <UIApplicationDelegate> | |
@property (strong, nonatomic) UIWindow *window; | |
@property (strong, nonatomic) NSString *info; | |
-(void)doSomethingWithString:(NSString*)parameter; | |
-(NSString*)getInfo; | |
@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
@interface MySingleton : NSObject{ | |
NSString *info; | |
} | |
+(MySingleton*) getInstance; | |
-(void)doSomethingWithString:(NSString*)parameter; | |
-(NSString*)getInfo; | |
@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 "MySingleton.h" | |
@implementation MySingleton | |
static MySingleton *singletonInstance; | |
+ (MySingleton*)getInstance{ | |
if (singletonInstance == nil) { | |
singletonInstance = [[super alloc] init]; | |
} | |
return singletonInstance; | |
} | |
-(void)doSomethingWithString:(NSString*)parameter { | |
info = parameter; | |
} | |
-(NSString*)getInfo { | |
return info; | |
} | |
@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> | |
@interface ViewController : UIViewController | |
- (IBAction)tappedSaveData:(id)sender; | |
- (IBAction)tappedLoadData:(id)sender; | |
@property (weak, nonatomic) IBOutlet UILabel *lblInfo; | |
@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
- (IBAction)tappedSaveData:(id)sender { | |
AppDelegate *delegate = [UIApplication sharedApplication].delegate; | |
delegate.info = @"Some text!"; | |
} | |
- (IBAction)tappedLoadData:(id)sender { | |
AppDelegate *delegate = [UIApplication sharedApplication].delegate; | |
[self.lblInfo setText:delegate.info]; | |
} |
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
- (IBAction)tappedSaveData:(id)sender { | |
AppDelegate *delegate = [UIApplication sharedApplication].delegate; | |
[delegate doSomethingWithString:@"some text"]; | |
} | |
- (IBAction)tappedLoadData:(id)sender { | |
AppDelegate *delegate = [UIApplication sharedApplication].delegate; | |
[self.lblInfo setText:[delegate getInfo]]; | |
} |
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
- (IBAction)tappedSaveData:(id)sender { | |
// AppDelegate *delegate = [UIApplication sharedApplication].delegate; | |
// [delegate doSomethingWithString:@"some text"] | |
MySingleton* singleton = [MySingleton getInstance]; | |
[singleton doSomethingWithString:@"some text"]; | |
} | |
- (IBAction)tappedLoadData:(id)sender { | |
// AppDelegate *delegate = [UIApplication sharedApplication].delegate; | |
// [self.lblInfo setText:[delegate getInfo]]; | |
MySingleton* singleton = [MySingleton getInstance]; | |
[self.lblInfo setText:[singleton getInfo]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment