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
| - (CGFloat)mapWithValue:(CGFloat)value inMin:(CGFloat)inMin inMax:(CGFloat)inMax outMin:(CGFloat)outMin outMax:(CGFloat)outMax | |
| { | |
| return (value - inMin) / (inMax - inMin) * (outMax - outMin) + outMin; | |
| } |
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
| // 年、月、日から曜日を返す | |
| // 0:日曜日 .. 6:土曜日 | |
| @warn_unused_result | |
| func dayOfWeek(var m:Int, _ d:Int, var year y:Int = 2016) -> Int { | |
| if m < 3 { | |
| m += 12; --y | |
| } | |
| let leap = y + y / 4 - y / 100 + y / 400 | |
| return (leap + (13 * m + 8) / 5 + d) % 7 |
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
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
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
| //block宣言部 | |
| //call.h | |
| typedef void (^callback)(NSError *error); | |
| +(void)callbackSample:(callback)_callback; | |
| //call.m | |
| +(void)callbackSample:(callback)_callback |
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
| + (NSString *)applicationDocumentsDirectory | |
| { | |
| NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
| NSString *documentsDirectory = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; | |
| return documentsDirectory; |
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
| //通知の登録はviewWillAppear | |
| -(void)viewWillAppear:(BOOL)animated | |
| { | |
| [super viewWillAppear:animated]; | |
| NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; | |
| [nc addObserver:self selector:@selector(doNotif:) name@"notif" object:nil]; | |
| } | |
| //通知の解除はviewWillDisappear |
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
| //.h | |
| +(ModelManager*)sharedManager; | |
| //.m | |
| static ModelManager* _sharedInstance = nil; | |
| +(ModelManager*)sharedManager | |
| { | |
| if(!_sharedInstance){ |
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
| NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; | |
| //保存 | |
| [ud setInteger:1 forKey:@"KEY_I"]; | |
| [ud synchronize];//即時反映したい場合のみ | |
| //読み込み | |
| [ud integerForKey:@"KEY_I"]; | |
| //削除 |
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
| //main threadで起動する方法 | |
| dispatch_async( | |
| dispatch_get_main_queue(), ^{ | |
| //行いたい処理を記述する | |
| //例えばviewの遷移 | |
| [self dismissViewControllerAnimated:YES completion:nil]; | |
| } | |
| ); | |
| //main threadかどうかを確認 |
NewerOlder