[objective-c]使用言語を調べる
使用言語を調べる
NSString*lang=[self getCurrentLanguage]; -(NSString*)getCurrentLanguage { NSArray *languages = [NSLocale preferredLanguages]; return [languages objectAtIndex:0]; }
使用言語を調べる
NSString*lang=[self getCurrentLanguage]; -(NSString*)getCurrentLanguage { NSArray *languages = [NSLocale preferredLanguages]; return [languages objectAtIndex:0]; }
ビット演算#1
type(INTEGER)を4ビット右シフトして右端が1であるレコードのidとtypeを取得する。
SELECT id,type FROM target_table_name WHERE type >> 4 & 1 = 1;
2つの日付の差を日数で出す
int dayCount = [self getDaysCountByTwoDateString:@"2014-04-01" endDateString:@"2014-04-04"]; -(int)getDaysCountByTwoDateString:(NSString*)startDateString endDateString:(NSString*)endDateString { NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init]; [inputDateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate *startInputDate = [inputDateFormatter dateFromString:startDateString]; NSDate *endInputDate = [inputDateFormatter dateFromString:endDateString]; float tmp= [endInputDate timeIntervalSinceDate:startInputDate]; int day=(int)( tmp / (3600.0*24.0) ); return day; }
URLを取得
$url = (empty($_SERVER["HTTPS"]) ? "http://" : "https://") . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]
animateWithDurationを途中で止める
アニメーション実行
[UIView animateWithDuration:10.0f animations:^{ targetView.frame=CGRectMalke(0.0,0.0,100.0,100.0); } completion:^(BOOL finished) { }];
アニメーション中止
[UIView setAnimationBeginsFromCurrentState:YES]; [UIView animateWithDuration:0.001 animations:^{ targetView.alpha = 1.0; }];
$.ajaxでcookieも送信
IE10未満は不可
$.ajax({ type:'post', url:'url', dataType:'text', data:data, crossDomain:true, cache:false, xhrFields: { withCredentials:true }, success:function(data, dataType){ }, error:function(XMLHttpRequest, textStatus, errorThrown){ }, complete:function(){ } });
数字の桁を合わせる
NSString*numStr1=[NSString stringWithFormat:@"%02d",i];//2桁 NSString*numStr2=[NSString stringWithFormat:@"%04d",i];//4桁 i=3のとき"0003"となる
pagingEnabled=YESのUIScrollViewのスクロール先のページインデックスを取得
ヘッダーファイル
<UIScrollViewDelegate>
メインファイル
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { CGFloat width = scrollView.frame.size.width; NSInteger page = (targetContentOffset->x + (0.5f * width)) / width; int index=(int)page; }
文字列に指定の文字列が含まれているか判定
BOOL has = [self hasSpecifiedString:@"abcdefg" searchString:@"cde"]; -(BOOL)hasSpecifiedString:(NSString*)targetString searchString:(NSString*)searchString { NSRange searchResult = [targetString rangeOfString:searchString]; return !(searchResult.location==NSNotFound); }
performSelectorの警告を消す
#define SuppressPerformSelectorLeakWarning(Stuff) \ do { \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \ Stuff; \ _Pragma("clang diagnostic pop") \ } while (0)
if (_delegate && _selector && [_delegate respondsToSelector:_selector]) { SuppressPerformSelectorLeakWarning([_delegate performSelector:_selector withObject:[NSNumber numberWithBool:success]]); }